summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/fs/node.js3
-rw-r--r--lib/models/fs.js29
-rw-r--r--lib/utils/fs.js1
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/fs/node.js b/lib/fs/node.js
index 9b8c056..dfe9fae 100644
--- a/lib/fs/node.js
+++ b/lib/fs/node.js
@@ -36,6 +36,7 @@ module.exports = function createNodeFS(root) {
fsReadFile: fs.readFile,
fsStatFile: fs.stat,
fsReadDir: fsReadDir,
- fsLoadObject: fsLoadObject
+ fsLoadObject: fsLoadObject,
+ fsReadAsStream: fs.readStream
});
};
diff --git a/lib/models/fs.js b/lib/models/fs.js
index ab65dd5..12aee53 100644
--- a/lib/models/fs.js
+++ b/lib/models/fs.js
@@ -1,5 +1,6 @@
var path = require('path');
var Immutable = require('immutable');
+var stream = require('stream');
var File = require('./file');
var Promise = require('../utils/promise');
@@ -13,7 +14,9 @@ var FS = Immutable.Record({
fsReadFile: Function(),
fsStatFile: Function(),
fsReadDir: Function(),
- fsLoadObject: null
+
+ fsLoadObject: null,
+ fsReadAsStream: null
});
/**
@@ -112,6 +115,30 @@ FS.prototype.readAsString = function(filename, encoding) {
};
/**
+ Read file as a stream
+
+ @param {String} filename
+ @return {Promise<Stream>}
+*/
+FS.prototype.readAsStream = function(filename) {
+ var that = this;
+ var filepath = that.resolve(filename);
+ var fsReadAsStream = this.get('fsReadAsStream');
+
+ if (fsReadAsStream) {
+ return Promise(fsReadAsStream(filepath));
+ }
+
+ return this.read(filename)
+ .then(function(buf) {
+ var bufferStream = new stream.PassThrough();
+ bufferStream.end(buf);
+
+ return bufferStream;
+ });
+};
+
+/**
Read stat infos about a file
@param {String} filename
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index da22fdb..35839a3 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -157,6 +157,7 @@ module.exports = {
statSync: fs.statSync,
readdir: Promise.nfbind(fs.readdir),
writeStream: writeStream,
+ readStream: fs.createReadStream,
copy: Promise.nfbind(cp),
copyDir: Promise.nfbind(cpr),
tmpFile: genTmpFile,