admin管理员组

文章数量:1341406

Here is what I want to do:

stream = fs.WriteStream('crap.txt',{flags:'w'};
// more code
response.on('close',function() {
      // is the below line possible?
      fs.stat(stream.name, function(stats) {
            console.log(stats.size);
      });
      stream.end();
});

So can I get the filename from the stream object? An illustrated example would be nice, with reference to good tutorial/docs (containing examples) on writable streams.

Here is what I want to do:

stream = fs.WriteStream('crap.txt',{flags:'w'};
// more code
response.on('close',function() {
      // is the below line possible?
      fs.stat(stream.name, function(stats) {
            console.log(stats.size);
      });
      stream.end();
});

So can I get the filename from the stream object? An illustrated example would be nice, with reference to good tutorial/docs (containing examples) on writable streams.

Share edited Apr 16, 2013 at 0:12 ASGM 11.4k1 gold badge37 silver badges54 bronze badges asked Apr 16, 2013 at 0:09 fedvasufedvasu 1,2523 gold badges18 silver badges41 bronze badges 1
  • 1 Not an answer, but writeStream.bytesWritten exists. – AncientSwordRage Commented Jan 10, 2022 at 3:25
Add a ment  | 

1 Answer 1

Reset to default 12

It's fs.createWriteStream and stream.path

You can console.dir(stream) to find all it's properties

本文标签: javascriptHow to get name of file from writeStreamStack Overflow