From e46c7d6f695427af4f3b7f06213b8c3deb679b68 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Wed, 19 Jan 2022 18:27:04 +0200 Subject: [PATCH] doc: deprecate `buffer.slice` PR-URL: https://github.com/nodejs/node/pull/41596 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel --- doc/api/buffer.md | 12 ++++++++---- doc/api/deprecations.md | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 67863b4e099d18..657041b306101d 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -252,7 +252,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. @@ -2038,7 +2038,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`. @@ -3371,6 +3371,9 @@ console.log(buf.subarray(-5, -2).toString()); + +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 @@ -3054,6 +3070,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