Skip to content

Commit 2e7bf00

Browse files
benjamingrBethGriggs
authored andcommitted
doc: deprecate buffer.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 e500d11 commit 2e7bf00

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

doc/api/buffer.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ In particular:
254254
without copying. This behavior can be surprising, and only exists for legacy
255255
compatibility. [`TypedArray.prototype.subarray()`][] can be used to achieve
256256
the behavior of [`Buffer.prototype.slice()`][`buf.slice()`] on both `Buffer`s
257-
and other `TypedArray`s.
257+
and other `TypedArray`s and should be preferred.
258258
* [`buf.toString()`][] is incompatible with its `TypedArray` equivalent.
259259
* A number of methods, e.g. [`buf.indexOf()`][], support additional arguments.
260260

@@ -2054,7 +2054,7 @@ If `value` is:
20542054
* a string, `value` is interpreted according to the character encoding in
20552055
`encoding`.
20562056
* a `Buffer` or [`Uint8Array`][], `value` will be used in its entirety.
2057-
To compare a partial `Buffer`, use [`buf.slice()`][].
2057+
To compare a partial `Buffer`, use [`buf.subarray`][].
20582058
* a number, `value` will be interpreted as an unsigned 8-bit integer
20592059
value between `0` and `255`.
20602060

@@ -3387,6 +3387,9 @@ console.log(buf.subarray(-5, -2).toString());
33873387
<!-- YAML
33883388
added: v0.3.0
33893389
changes:
3390+
- version: REPLACEME
3391+
pr-url: https://github.com/nodejs/node/pull/41596
3392+
description: The buf.slice() method has been deprecated.
33903393
- version:
33913394
- v7.1.0
33923395
- v6.9.2
@@ -3404,11 +3407,11 @@ changes:
34043407
**Default:** [`buf.length`][].
34053408
* Returns: {Buffer}
34063409

3410+
> Stability: 0 - Deprecated: Use [`buf.subarray`][] instead.
3411+
34073412
Returns a new `Buffer` that references the same memory as the original, but
34083413
offset and cropped by the `start` and `end` indices.
34093414

3410-
This is the same behavior as `buf.subarray()`.
3411-
34123415
This method is not compatible with the `Uint8Array.prototype.slice()`,
34133416
which is a superclass of `Buffer`. To copy the slice, use
34143417
`Uint8Array.prototype.slice()`.
@@ -5369,6 +5372,7 @@ introducing security vulnerabilities into an application.
53695372
[`buf.keys()`]: #bufkeys
53705373
[`buf.length`]: #buflength
53715374
[`buf.slice()`]: #bufslicestart-end
5375+
[`buf.subarray`]: #bufsubarraystart-end
53725376
[`buf.toString()`]: #buftostringencoding-start-end
53735377
[`buf.values()`]: #bufvalues
53745378
[`buffer.constants.MAX_LENGTH`]: #bufferconstantsmax_length

doc/api/deprecations.md

+17
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,22 @@ const w = new Writable({
30453045
});
30463046
```
30473047

3048+
### DEP0158: `buffer.slice(start, end)`
3049+
3050+
<!-- YAML
3051+
changes:
3052+
- version: REPLACEME
3053+
pr-url: https://github.com/nodejs/node/pull/41596
3054+
description: Documentation-only deprecation.
3055+
-->
3056+
3057+
Type: Documentation-only
3058+
3059+
This method was deprecated because it is not compatible with
3060+
`Uint8Array.prototype.slice()`, which is a superclass of `Buffer`.
3061+
3062+
Use [`buffer.subarray`][] which does the same thing instead.
3063+
30483064
[Legacy URL API]: url.md#legacy-url-api
30493065
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
30503066
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -3067,6 +3083,7 @@ const w = new Writable({
30673083
[`WriteStream.open()`]: fs.md#class-fswritestream
30683084
[`assert`]: assert.md
30693085
[`asyncResource.runInAsyncScope()`]: async_context.md#asyncresourceruninasyncscopefn-thisarg-args
3086+
[`buffer.subarray`]: buffer.md#bufsubarraystart-end
30703087
[`child_process`]: child_process.md
30713088
[`clearInterval()`]: timers.md#clearintervaltimeout
30723089
[`clearTimeout()`]: timers.md#cleartimeouttimeout

0 commit comments

Comments
 (0)