Skip to content

Commit e46c7d6

Browse files
benjamingrdanielleadams
authored andcommitted
doc: deprecate buffer.slice
PR-URL: #41596 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 0be2321 commit e46c7d6

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
@@ -252,7 +252,7 @@ In particular:
252252
without copying. This behavior can be surprising, and only exists for legacy
253253
compatibility. [`TypedArray.prototype.subarray()`][] can be used to achieve
254254
the behavior of [`Buffer.prototype.slice()`][`buf.slice()`] on both `Buffer`s
255-
and other `TypedArray`s.
255+
and other `TypedArray`s and should be preferred.
256256
* [`buf.toString()`][] is incompatible with its `TypedArray` equivalent.
257257
* A number of methods, e.g. [`buf.indexOf()`][], support additional arguments.
258258

@@ -2038,7 +2038,7 @@ If `value` is:
20382038
* a string, `value` is interpreted according to the character encoding in
20392039
`encoding`.
20402040
* a `Buffer` or [`Uint8Array`][], `value` will be used in its entirety.
2041-
To compare a partial `Buffer`, use [`buf.slice()`][].
2041+
To compare a partial `Buffer`, use [`buf.subarray`][].
20422042
* a number, `value` will be interpreted as an unsigned 8-bit integer
20432043
value between `0` and `255`.
20442044

@@ -3371,6 +3371,9 @@ console.log(buf.subarray(-5, -2).toString());
33713371
<!-- YAML
33723372
added: v0.3.0
33733373
changes:
3374+
- version: REPLACEME
3375+
pr-url: https://github.com/nodejs/node/pull/41596
3376+
description: The buf.slice() method has been deprecated.
33743377
- version:
33753378
- v7.1.0
33763379
- v6.9.2
@@ -3388,11 +3391,11 @@ changes:
33883391
**Default:** [`buf.length`][].
33893392
* Returns: {Buffer}
33903393

3394+
> Stability: 0 - Deprecated: Use [`buf.subarray`][] instead.
3395+
33913396
Returns a new `Buffer` that references the same memory as the original, but
33923397
offset and cropped by the `start` and `end` indices.
33933398

3394-
This is the same behavior as `buf.subarray()`.
3395-
33963399
This method is not compatible with the `Uint8Array.prototype.slice()`,
33973400
which is a superclass of `Buffer`. To copy the slice, use
33983401
`Uint8Array.prototype.slice()`.
@@ -5349,6 +5352,7 @@ introducing security vulnerabilities into an application.
53495352
[`buf.keys()`]: #bufkeys
53505353
[`buf.length`]: #buflength
53515354
[`buf.slice()`]: #bufslicestart-end
5355+
[`buf.subarray`]: #bufsubarraystart-end
53525356
[`buf.toString()`]: #buftostringencoding-start-end
53535357
[`buf.values()`]: #bufvalues
53545358
[`buffer.constants.MAX_LENGTH`]: #bufferconstantsmax_length

doc/api/deprecations.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,22 @@ const w = new Writable({
30323032
});
30333033
```
30343034

3035+
### DEP0158: `buffer.slice(start, end)`
3036+
3037+
<!-- YAML
3038+
changes:
3039+
- version: REPLACEME
3040+
pr-url: https://github.com/nodejs/node/pull/41596
3041+
description: Documentation-only deprecation.
3042+
-->
3043+
3044+
Type: Documentation-only
3045+
3046+
This method was deprecated because it is not compatible with
3047+
`Uint8Array.prototype.slice()`, which is a superclass of `Buffer`.
3048+
3049+
Use [`buffer.subarray`][] which does the same thing instead.
3050+
30353051
[Legacy URL API]: url.md#legacy-url-api
30363052
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
30373053
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -3054,6 +3070,7 @@ const w = new Writable({
30543070
[`WriteStream.open()`]: fs.md#class-fswritestream
30553071
[`assert`]: assert.md
30563072
[`asyncResource.runInAsyncScope()`]: async_context.md#asyncresourceruninasyncscopefn-thisarg-args
3073+
[`buffer.subarray`]: buffer.md#bufsubarraystart-end
30573074
[`child_process`]: child_process.md
30583075
[`clearInterval()`]: timers.md#clearintervaltimeout
30593076
[`clearTimeout()`]: timers.md#cleartimeouttimeout

0 commit comments

Comments
 (0)