Node: How to wait until a file is completed before processing it?

后端 未结 2 1031
醉话见心
醉话见心 2021-02-20 17:39

My Problem is that I can not be sure when a file has been successfully written to and the file has been closed. Consider the following case:

var fs = require(\'f         


        
相关标签:
2条回答
  • 2021-02-20 18:09

    Do your file's post-processing in the writeable stream's close event:

    outs.on('close', function() {
      <<spawn your process>>
    });
    

    Also, no need for the destroySoon after the end, they are one and the same.

    0 讨论(0)
  • 2021-02-20 18:10

    Check out https://github.com/TomFrost/FlushWritable – I don't know why it's not written into the Writable core but this should do the trick.

    Also, there's a discussion addressing this on GitHub https://github.com/nodejs/node-v0.x-archive/issues/7348.

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