Skip to content

Commit

Permalink
New: Add isDirectory method
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra authored and phated committed Sep 27, 2016
1 parent 491f1a4 commit 0038568
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ File.prototype.isNull = function() {
return isNull(this.contents);
};

File.prototype.isDirectory = function() {
return this.isNull() && this.stat && this.stat.isDirectory();
};

File.prototype.clone = function() {
var clonedStat = clone(this.stat);
var clonedContents = this.isBuffer() ? cloneBuffer(this.contents) : this.contents;
Expand Down
28 changes: 28 additions & 0 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ describe('File', function() {
});
});

describe('isDirectory()', function() {
var fakeStat = {
isDirectory: function() {
return true;
}
};

it('should return false when the contents are a Buffer', function(done) {
var val = new Buffer("test");
var file = new File({contents: val, stat: fakeStat});
file.isDirectory().should.equal(false);
done();
});

it('should return false when the contents are a Stream', function(done) {
var val = new Stream();
var file = new File({contents: val, stat: fakeStat});
file.isDirectory().should.equal(false);
done();
});

it('should return true when the contents are a null', function(done) {
var file = new File({contents: null, stat: fakeStat});
file.isDirectory().should.equal(true);
done();
});
});

describe('clone()', function() {
it('should copy all attributes over with Buffer', function(done) {
var options = {
Expand Down

0 comments on commit 0038568

Please sign in to comment.