From 28ee4f41a1b19605fe147dd333bab07862876e41 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 8 Apr 2014 00:26:20 -0700 Subject: [PATCH] Fix copy with typed arrays Creating a new `Uint8Array` from the `this.buffer` doesn't work if `subarray` had previously been used (e.g. `slice`), since `this.buffer` still would refer to the start of the buffer, not the start of the subarray. We can use `subarray` here instead, which keeps previous subarray indices intact. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 911507b..57e1178 100644 --- a/index.js +++ b/index.js @@ -395,7 +395,7 @@ Buffer.prototype.copy = function (target, target_start, start, end) { for (var i = 0; i < len; i++) target[i + target_start] = this[i + start] } else { - target._set(new Uint8Array(this.buffer, start, len), target_start) + target._set(this.subarray(start, start + len), target_start) } } -- 2.34.1