Skip to content

Commit 9e0fd77

Browse files
committed
[minor] Use Buffer#subarray() instead of Buffer#slice()
`Buffer.prototype.slice()` is deprecated.
1 parent a6fa37a commit 9e0fd77

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/buffer-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function concat(list, totalLength) {
2323
offset += buf.length;
2424
}
2525

26-
if (offset < totalLength) return target.slice(0, offset);
26+
if (offset < totalLength) return target.subarray(0, offset);
2727

2828
return target;
2929
}

lib/permessage-deflate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class PerMessageDeflate {
437437
this._deflate[kTotalLength]
438438
);
439439

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

442442
//
443443
// Ensure that the callback will not be called again in

lib/receiver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class Receiver extends Writable {
9797

9898
if (n < this._buffers[0].length) {
9999
const buf = this._buffers[0];
100-
this._buffers[0] = buf.slice(n);
101-
return buf.slice(0, n);
100+
this._buffers[0] = buf.subarray(n);
101+
return buf.subarray(0, n);
102102
}
103103

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

117117
n -= buf.length;
@@ -562,7 +562,7 @@ class Receiver extends Writable {
562562
);
563563
}
564564

565-
const buf = data.slice(2);
565+
const buf = data.subarray(2);
566566

567567
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
568568
return error(

0 commit comments

Comments
 (0)