Nodejs没有写文件 [英] Nodejs not writing the files

查看:138
本文介绍了Nodejs没有写文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是nodejs的新手。当我试图运行以下代码时,它没有给我正确的输出。据我所知,下面的程序将生成一个'tmp.torrent'文件。但它没有发生。



我尝试过:



I am new to nodejs. When i tried to run the below code, it not giving me the correct out put. according to me the below program will generate a 'tmp.torrent' file . But it is not happening.

What I have tried:

var Torrent = require('webseeded-torrent-generator');
var fs = require('fs');
var base = 'http://ia700201.us.archive.org/6/items/';
var name = 'jj2005-02-27.fm.shnf';
var files = [
    'jj2005-02-27.fm.d1.md5',
    'jj2005-02-27.fm.d1.txt'
];
 
var torrent = new Torrent(base, name, files);
torrent.getMetadata().then(function (buf) {
    fs.writeFileSync('tmp.torrent', buf);
});

推荐答案





似乎你没有处理错误,可能还有一些连接问题,我想



Hi,

seems you are not handling error, and probably there are some connectivity issues, I suppose

torrent.getMetadata().then(function data (buf) {
  fs.writeFileSync('tmp.torrent', buf)
}, function err (err) {
  console.log('ERR', err)
})





看错误,处理它......



see error, handle it...


这篇关于Nodejs没有写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆