Skip to content

Commit 830cbca

Browse files
benjamingraduh95
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 290911b commit 830cbca

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

doc/api/buffer.md

Lines changed: 8 additions & 4 deletions
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

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

@@ -3389,6 +3389,9 @@ console.log(buf.subarray(-5, -2).toString());
33893389
<!-- YAML
33903390
added: v0.3.0
33913391
changes:
3392+
- version: REPLACEME
3393+
pr-url: https://github.com/nodejs/node/pull/41596
3394+
description: The buf.slice() method has been deprecated.
33923395
- version:
33933396
- v7.1.0
33943397
- v6.9.2
@@ -3406,11 +3409,11 @@ changes:
34063409
**Default:** [`buf.length`][].
34073410
* Returns: {Buffer}
34083411

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

3412-
This is the same behavior as `buf.subarray()`.
3413-
34143417
This method is not compatible with the `Uint8Array.prototype.slice()`,
34153418
which is a superclass of `Buffer`. To copy the slice, use
34163419
`Uint8Array.prototype.slice()`.
@@ -5371,6 +5374,7 @@ introducing security vulnerabilities into an application.
53715374
[`buf.keys()`]: #bufkeys
53725375
[`buf.length`]: #buflength
53735376
[`buf.slice()`]: #bufslicestart-end
5377+
[`buf.subarray`]: #bufsubarraystart-end
53745378
[`buf.toString()`]: #buftostringencoding-start-end
53755379
[`buf.values()`]: #bufvalues
53765380
[`buffer.constants.MAX_LENGTH`]: #bufferconstantsmax_length

doc/api/deprecations.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,22 @@ const w = new Writable({
30403040
});
30413041
```
30423042

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

0 commit comments

Comments
 (0)