Skip to content

Commit 84752a4

Browse files
benjamingrdanielleadams
authored andcommitted
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 3d4df9c commit 84752a4

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
@@ -1113,14 +1113,18 @@ function adjustOffset(offset, length) {
11131113
return NumberIsNaN(offset) ? 0 : length;
11141114
}
11151115

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

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

0 commit comments

Comments
 (0)