Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between fs.ReadStream and fs.createReadStream in Node.js?

Tags:

stream

node.js

fs

In fs module in Node.js, is there any difference between fs.ReadStream and fs.createReadStream? As far as I know, both take filename and then create stream object...right?

like image 402
Blaszard Avatar asked Mar 23 '23 17:03

Blaszard


1 Answers

No

https://github.com/nodejs/node/blob/1124de2d76ad7118267d91a08485aa928a5f0865/lib/fs.js#L1711

fs.createReadStream = function(path, options) {
  return new ReadStream(path, options);
};

Fine print: YES. fs.createReadStream costs you 1 extra wrapper function call

like image 181
Peter Lyons Avatar answered Apr 24 '23 19:04

Peter Lyons