Skip to content

Commit

Permalink
[minor] Use Buffer#subarray() instead of Buffer#slice()
Browse files Browse the repository at this point in the history
`Buffer.prototype.slice()` is deprecated.
  • Loading branch information
lpinca committed Dec 12, 2022
1 parent a6fa37a commit 9e0fd77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/buffer-util.js
Expand Up @@ -23,7 +23,7 @@ function concat(list, totalLength) {
offset += buf.length;
}

if (offset < totalLength) return target.slice(0, offset);
if (offset < totalLength) return target.subarray(0, offset);

return target;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/permessage-deflate.js
Expand Up @@ -437,7 +437,7 @@ class PerMessageDeflate {
this._deflate[kTotalLength]
);

if (fin) data = data.slice(0, data.length - 4);
if (fin) data = data.subarray(0, data.length - 4);

//
// Ensure that the callback will not be called again in
Expand Down
8 changes: 4 additions & 4 deletions lib/receiver.js
Expand Up @@ -97,8 +97,8 @@ class Receiver extends Writable {

if (n < this._buffers[0].length) {
const buf = this._buffers[0];
this._buffers[0] = buf.slice(n);
return buf.slice(0, n);
this._buffers[0] = buf.subarray(n);
return buf.subarray(0, n);
}

const dst = Buffer.allocUnsafe(n);
Expand All @@ -111,7 +111,7 @@ class Receiver extends Writable {
dst.set(this._buffers.shift(), offset);
} else {
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
this._buffers[0] = buf.slice(n);
this._buffers[0] = buf.subarray(n);
}

n -= buf.length;
Expand Down Expand Up @@ -562,7 +562,7 @@ class Receiver extends Writable {
);
}

const buf = data.slice(2);
const buf = data.subarray(2);

if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
return error(
Expand Down

0 comments on commit 9e0fd77

Please sign in to comment.