Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
31 changes: 27 additions & 4 deletions lib/filewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,35 @@ function Filewalker(root, options) {
var self = this;

this.matchRegExp = null;

this.recursive = true;

options = options || {};

var readStreamOptions = {
flags: 'r',
encoding: null,
fd: null,
mode: 0666,
autoClose: true,
highWaterMark: 64 * 1024
};

if ( ! options.readStream ) {
options.readStream = readStreamOptions;
} else {
// Overwrite only the specified properties
for ( var i in options.readStream ) {
readStreamOptions[ i ] = options.readStream[ i ];
}
options.readStream = readStreamOptions;
}

this.readStream = options.readStream;

// Copy all the options properties to this, except 'readStream'
Object.keys(options).forEach(function(k) {
if(self.hasOwnProperty(k)) {
if( self.hasOwnProperty(k) ) {
self[k] = options[k];
}
});
Expand Down Expand Up @@ -85,7 +108,7 @@ Filewalker.prototype._emitStream = function(p, s, fullPath) {

this.open += 1;

var rs = fs.ReadStream(fullPath);
var rs = fs.ReadStream(fullPath, this.readStream);

// retry on any error
rs.on('error', function(err) {
Expand Down
21 changes: 21 additions & 0 deletions test/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,25 @@ describe('Filewalker', function() {
fw.walk();
});
});

describe('feature: use given readStream options', function() {
var myHighWaterMark = 1024*1024;
var fw;
before(function() {
fw = filewalker(examplesFile, { readStream: { highWaterMark: myHighWaterMark } } );
});
after(function() {
fw = null;
});
it('when "stream", it should be using the given readStream option', function(done) {
fw.on('stream', function(rs, p, s, fullPath) {
assert.strictEqual( fw.readStream.highWaterMark, myHighWaterMark );
assert.strictEqual( fw.readStream.highWaterMark, rs._readableState.highWaterMark );
reallyReadTheReadStream(rs);
});
fw.on('done', done);
fw.walk();
});

});
});