Skip to content

Commit 89c3273

Browse files
benjamingrBethGriggs
authored andcommittedJan 24, 2022
buffer: alias subarray and slice
PR-URL: #41596 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 6fefd51 commit 89c3273

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎lib/buffer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,18 @@ function adjustOffset(offset, length) {
11121112
return NumberIsNaN(offset) ? 0 : length;
11131113
}
11141114

1115-
Buffer.prototype.slice = function slice(start, end) {
1115+
Buffer.prototype.subarray = function subarray(start, end) {
11161116
const srcLength = this.length;
11171117
start = adjustOffset(start, srcLength);
11181118
end = end !== undefined ? adjustOffset(end, srcLength) : srcLength;
11191119
const newLength = end > start ? end - start : 0;
11201120
return new FastBuffer(this.buffer, this.byteOffset + start, newLength);
11211121
};
11221122

1123+
Buffer.prototype.slice = function slice(start, end) {
1124+
return this.subarray(start, end);
1125+
};
1126+
11231127
function swap(b, n, m) {
11241128
const i = b[n];
11251129
b[n] = b[m];

0 commit comments

Comments
 (0)
Please sign in to comment.