Skip to content

Commit

Permalink
fix: avoid overriding Transform.destroy() method
Browse files Browse the repository at this point in the history
- fix compatibility with Node 14
  • Loading branch information
curbengh committed Apr 24, 2020
1 parent 5b14fd2 commit dca1360
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 0 additions & 4 deletions lib/cache_stream.js
Expand Up @@ -18,10 +18,6 @@ CacheStream.prototype._transform = function(chunk, enc, callback) {
callback();
};

CacheStream.prototype.destroy = function() {
this._cache.length = 0;
};

CacheStream.prototype.getCache = function() {
return Buffer.concat(this._cache);
};
Expand Down
12 changes: 10 additions & 2 deletions test/cache_stream.spec.js
Expand Up @@ -22,10 +22,18 @@ describe('CacheStream', () => {
});

it('destroy', () => {
const src = new Readable();
const cacheStream = new CacheStream();
cacheStream._cache = [Buffer.alloc(1)];
const content = Buffer.from('test');

src.push(content);
src.push(null);
src.pipe(cacheStream);

cacheStream.destroy();
cacheStream._cache.should.have.length(0);

cacheStream.on('close', () => {
cacheStream.getCache().length.should.eql(0);
});
});
});

0 comments on commit dca1360

Please sign in to comment.