file-source
Version:
Read binary files in chunks, on demand, with promises.
13 lines (11 loc) • 437 B
JavaScript
var fs = require("fs"),
stream = require("stream-source");
module.exports = function(path, options) {
var highWaterMark = 65536;
if (options && options.highWaterMark != null) highWaterMark = options.highWaterMark;
return new Promise(function(resolve, reject) {
var f = fs.createReadStream(path, {highWaterMark: highWaterMark});
f.once("open", function() { resolve(stream(f)); });
f.once("error", reject);
});
};