From df47d58d7414b76f1b705ac0bc1aa5102e88ae57 Mon Sep 17 00:00:00 2001 From: jeromew Date: Fri, 15 Mar 2019 10:12:20 +0000 Subject: [PATCH] Do not register the pushBufferIfNeeded method on the instance --- copy-to.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/copy-to.js b/copy-to.js index 5947bdd..557c55b 100644 --- a/copy-to.js +++ b/copy-to.js @@ -47,9 +47,10 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { var buffer = Buffer.alloc(chunk.length); var buffer_offset = 0; - this.pushBufferIfneeded = function() { + var self = this; + var pushBufferIfneeded = function() { if (needPush && buffer_offset > 0) { - this.push(buffer.slice(0, buffer_offset)) + self.push(buffer.slice(0, buffer_offset)) buffer_offset = 0; } } @@ -82,7 +83,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { case code.ErrorResponse: case code.CopyDone: - this.pushBufferIfneeded(); + pushBufferIfneeded(); this._detach() this.push(null) return cb(); @@ -107,7 +108,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { } } - this.pushBufferIfneeded(); + pushBufferIfneeded(); if(chunk.length - offset) { var slice = chunk.slice(offset)