Skip to content

Commit

Permalink
Allow #read defaults options to be of any types
Browse files Browse the repository at this point in the history
Fix #60
  • Loading branch information
SBoudrias committed Jan 27, 2017
1 parent 1efcbb6 commit d356897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions __tests__/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ describe('#read()', function () {
var content = this.fs.read(fileA, {defaults: 'foo'});
assert.equal(content, 'foo');
});

it('allows defaults to be null', function () {
var content = this.fs.read('not-existing.file', {defaults: null});
assert.equal(content, null);
});
});
11 changes: 4 additions & 7 deletions lib/actions/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ module.exports = function (filepath, options) {
var file = this.store.get(filepath);

if (file.state === 'deleted' || file.contents === null) {
if (typeof options.defaults === 'string' || options.defaults instanceof Buffer) {
file.contents = new Buffer(options.defaults);
if ('defaults' in options) {
return options.defaults;
}
else {
file.contents = null;
}
}

assert(file.contents !== null, filepath + ' doesn\'t exist');
throw new Error(filepath + ' doesn\'t exist');
}

return options.raw ? file.contents : file.contents.toString();
};

0 comments on commit d356897

Please sign in to comment.