嗨,我目前正在玩 node,但出现了一个错误,我不知道如何解决:
stream.js:81
throw er; // Unhandled stream error in pipe.
Error: socket hang up
at createHangUpError (http.js:1344:15)
at Socket.socketOnEnd [as onend] (http.js:1432:23)
at TCP.onread (net.js:419:26)
我的脚本读取了一个文件,其中包含一个页面的 url,该页面本身包含我下载并保存的图像的 url。你能解释一下如何解决这个问题吗?对不起我的英语不好...
var fs = require('fs');
var request = require('request');
var lazy = require('lazy');
var lines = new lazy(fs.createReadStream('./' + dir + '/links.txt'))
.lines
.forEach(function (line) {
var req = request(line, function (error, res, body) {
if(res.statusCode == 200) {
var urlImg = body.match(/<img id="img".+?src="(.+?)"/)[1];
var stream = fs.createWriteStream(urlImg);
var req2 = request(urlImg).pipe(stream);
};
});
});