From 79621a597fac6d79d9ef32d90a4c8efc21d3e37e Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Wed, 19 Jan 2022 18:27:04 +0200 Subject: [PATCH] buffer: deprecate buffer.slice --- doc/api/buffer.md | 12 ++++++++---- doc/api/deprecations.md | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 80a97ababd2d06..b5d4a4e0e917f6 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()); + +Type: Documentation-only + +This method was deprecated because it is not compatible with the +`Uint8Array.prototype.slice()`, which is a superclass of `Buffer`. + +Use `buffer.subarray(start, end)` 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