84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
request(url).pipe(fs.createWriteStream(fpath)); var bu = fs.createReadStream(fpath, {start: 0, end: 262}); dlog(bu);
我先写入文件,再读取里面的东西,但是createReadStream读取不到东西。这是为什么?是因为上面的操作是异步进行的吗?如果是,那应该如何获取呢?
业精于勤,荒于嬉;行成于思,毁于随。
stream is an asynchronous operation. You will not get the result if you write it synchronously. So:
stream
request(url) .pipe(fs.createWriteStream(fpath)) .on('close', function() { var bu = fs.createReadStream(fpath, {start: 0, end: 262}); bu.on('data', function(chunk) { console.log(chunk.toString());//这是结果 }); });
See more documentation: fs
stream
is an asynchronous operation. You will not get the result if you write it synchronously. So:See more documentation: fs