Skip to content

Commit

Permalink
Breaking: Remove pipe method (closes #107)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 27, 2016
1 parent 0299890 commit 91073b4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 158 deletions.
27 changes: 0 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,6 @@ File.prototype.clone = function(opt) {
return file;
};

File.prototype.pipe = function(stream, opt) {
if (!opt) {
opt = {};
}
if (typeof opt.end === 'undefined') {
opt.end = true;
}

if (this.isStream()) {
return this.contents.pipe(stream, opt);
}
if (this.isBuffer()) {
if (opt.end) {
stream.end(this.contents);
} else {
stream.write(this.contents);
}
return stream;
}

// Check if isNull
if (opt.end) {
stream.end();
}
return stream;
};

File.prototype.inspect = function() {
var inspect = [];

Expand Down
131 changes: 0 additions & 131 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,137 +601,6 @@ describe('File', function() {
});
});

describe('pipe()', function() {
it('should write to stream with Buffer', function(done) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Buffer('test'),
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
});
stream.on('end', function() {
done();
});
var ret = file.pipe(stream);
ret.should.equal(stream, 'should return the stream');
});

it('should pipe to stream with Stream', function(done) {
var testChunk = new Buffer('test');
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Stream.PassThrough(),
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(testChunk.toString('utf8'));
done();
});
var ret = file.pipe(stream);
ret.should.equal(stream, 'should return the stream');

file.contents.write(testChunk);
});

it('should do nothing with null', function(done) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null,
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function() {
throw new Error('should not write');
});
stream.on('end', function() {
done();
});
var ret = file.pipe(stream);
ret.should.equal(stream, 'should return the stream');
});

it('should write to stream with Buffer', function(done) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Buffer('test'),
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(options.contents.toString('utf8'));
done();
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = file.pipe(stream, { end: false });
ret.should.equal(stream, 'should return the stream');
});

it('should pipe to stream with Stream', function(done) {
var testChunk = new Buffer('test');
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: new Stream.PassThrough(),
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function(chunk) {
should.exist(chunk);
(chunk instanceof Buffer).should.equal(true, 'should write as a buffer');
chunk.toString('utf8').should.equal(testChunk.toString('utf8'));
done();
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = file.pipe(stream, { end: false });
ret.should.equal(stream, 'should return the stream');

file.contents.write(testChunk);
});

it('should do nothing with null', function(done) {
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
contents: null,
};
var file = new File(options);
var stream = new Stream.PassThrough();
stream.on('data', function() {
throw new Error('should not write');
});
stream.on('end', function() {
throw new Error('should not end');
});
var ret = file.pipe(stream, { end: false });
ret.should.equal(stream, 'should return the stream');
process.nextTick(done);
});
});

describe('inspect()', function() {
it('should return correct format when no contents and no path', function(done) {
var file = new File();
Expand Down

0 comments on commit 91073b4

Please sign in to comment.