summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2022-01-19 18:27:04 +0200
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2022-01-22 00:34:36 +0100
commit830cbca8107bbddf5601384e257de6ba618fe5df (patch)
treeda1c32d06c3b9585fcecdd4a5dedacaeb05d482e
parent290911b99a13f6ecb0a6d8c33ba9d110c7059287 (diff)
downloadnode-new-830cbca8107bbddf5601384e257de6ba618fe5df.tar.gz
doc: deprecate `buffer.slice`
PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r--doc/api/buffer.md12
-rw-r--r--doc/api/deprecations.md17
2 files changed, 25 insertions, 4 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md
index 108ed091f5..9c5ed94f97 100644
--- a/doc/api/buffer.md
+++ b/doc/api/buffer.md
@@ -254,7 +254,7 @@ In particular:
without copying. This behavior can be surprising, and only exists for legacy
compatibility. [`TypedArray.prototype.subarray()`][] can be used to achieve
the behavior of [`Buffer.prototype.slice()`][`buf.slice()`] on both `Buffer`s
- and other `TypedArray`s.
+ and other `TypedArray`s and should be preferred.
* [`buf.toString()`][] is incompatible with its `TypedArray` equivalent.
* A number of methods, e.g. [`buf.indexOf()`][], support additional arguments.
@@ -2056,7 +2056,7 @@ If `value` is:
* a string, `value` is interpreted according to the character encoding in
`encoding`.
* a `Buffer` or [`Uint8Array`][], `value` will be used in its entirety.
- To compare a partial `Buffer`, use [`buf.slice()`][].
+ To compare a partial `Buffer`, use [`buf.subarray`][].
* a number, `value` will be interpreted as an unsigned 8-bit integer
value between `0` and `255`.
@@ -3389,6 +3389,9 @@ console.log(buf.subarray(-5, -2).toString());
<!-- YAML
added: v0.3.0
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/41596
+ description: The buf.slice() method has been deprecated.
- version:
- v7.1.0
- v6.9.2
@@ -3406,11 +3409,11 @@ changes:
**Default:** [`buf.length`][].
* Returns: {Buffer}
+> Stability: 0 - Deprecated: Use [`buf.subarray`][] instead.
+
Returns a new `Buffer` that references the same memory as the original, but
offset and cropped by the `start` and `end` indices.
-This is the same behavior as `buf.subarray()`.
-
This method is not compatible with the `Uint8Array.prototype.slice()`,
which is a superclass of `Buffer`. To copy the slice, use
`Uint8Array.prototype.slice()`.
@@ -5371,6 +5374,7 @@ introducing security vulnerabilities into an application.
[`buf.keys()`]: #bufkeys
[`buf.length`]: #buflength
[`buf.slice()`]: #bufslicestart-end
+[`buf.subarray`]: #bufsubarraystart-end
[`buf.toString()`]: #buftostringencoding-start-end
[`buf.values()`]: #bufvalues
[`buffer.constants.MAX_LENGTH`]: #bufferconstantsmax_length
diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md
index 2a879e693a..4cb8606c1f 100644
--- a/doc/api/deprecations.md
+++ b/doc/api/deprecations.md
@@ -3040,6 +3040,22 @@ const w = new Writable({
});
```
+### DEP0158: `buffer.slice(start, end)`
+
+<!-- YAML
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/41596
+ description: Documentation-only deprecation.
+-->
+
+Type: Documentation-only
+
+This method was deprecated because it is not compatible with
+`Uint8Array.prototype.slice()`, which is a superclass of `Buffer`.
+
+Use [`buffer.subarray`][] which does the same thing instead.
+
[Legacy URL API]: url.md#legacy-url-api
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -3062,6 +3078,7 @@ const w = new Writable({
[`WriteStream.open()`]: fs.md#class-fswritestream
[`assert`]: assert.md
[`asyncResource.runInAsyncScope()`]: async_context.md#asyncresourceruninasyncscopefn-thisarg-args
+[`buffer.subarray`]: buffer.md#bufsubarraystart-end
[`child_process`]: child_process.md
[`clearInterval()`]: timers.md#clearintervaltimeout
[`clearTimeout()`]: timers.md#cleartimeouttimeout