diff --git a/lib/buffer-util.js b/lib/buffer-util.js index 02973ae39..9de7b6c4b 100644 --- a/lib/buffer-util.js +++ b/lib/buffer-util.js @@ -19,7 +19,7 @@ function concat(list, totalLength) { for (let i = 0; i < list.length; i++) { const buf = list[i]; - buf.copy(target, offset); + target.set(buf, offset); offset += buf.length; } diff --git a/lib/receiver.js b/lib/receiver.js index 28ffca0f5..3a8b92a6b 100644 --- a/lib/receiver.js +++ b/lib/receiver.js @@ -96,11 +96,12 @@ class Receiver extends Writable { do { const buf = this._buffers[0]; + const offset = dst.length - n; if (n >= buf.length) { - this._buffers.shift().copy(dst, dst.length - n); + dst.set(this._buffers.shift(), offset); } else { - buf.copy(dst, dst.length - n, 0, n); + dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset); this._buffers[0] = buf.slice(n); }