event associated with fs.createWriteStream in node.js

前端 未结 1 1785
逝去的感伤
逝去的感伤 2020-12-13 14:18

What event is triggered when EOF is reached while writing to a stream ? My code is as follows. and it is as per http://docs.nodejitsu.com/articles/advanced/streams/how-to-us

1条回答
  •  囚心锁ツ
    2020-12-13 14:56

    Updated 30 Oct 2013

    Readable Steams emit close event when the underlying resource done writing.

    r.on('close', function(){
      console.log('request finished downloading file');
    });
    

    But if you want to catch the moment when fs finished writing data to the disc, you need Writeable Stream finish event:

    var w = fs.createWriteStream('/tmp/imageresize/'+x);
    
    request(options1).pipe(w);
    
    w.on('finish', function(){
      console.log('file downloaded to ', '/tmp/imageresize/'+x);
    });
    

    0 讨论(0)
提交回复
热议问题