From dca136098a9358c5c6cd0d4e2a019e0acf1738e1 Mon Sep 17 00:00:00 2001 From: MDLeom <43627182+curbengh@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:07:29 +0100 Subject: [PATCH] fix: avoid overriding Transform.destroy() method - fix compatibility with Node 14 --- lib/cache_stream.js | 4 ---- test/cache_stream.spec.js | 12 ++++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/cache_stream.js b/lib/cache_stream.js index 91e65124..54a38bc0 100644 --- a/lib/cache_stream.js +++ b/lib/cache_stream.js @@ -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); }; diff --git a/test/cache_stream.spec.js b/test/cache_stream.spec.js index 4b6766e4..1447f0aa 100644 --- a/test/cache_stream.spec.js +++ b/test/cache_stream.spec.js @@ -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); + }); }); });