diff --git a/index.js b/index.js index 29ae708..2e56f65 100644 --- a/index.js +++ b/index.js @@ -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 = []; diff --git a/test/File.js b/test/File.js index 7b63ee8..423dbd0 100644 --- a/test/File.js +++ b/test/File.js @@ -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();