Use subarray instead of the deprecated Buffer#slice - #35
Merged
NullVoxPopuli merged 1 commit intoSep 8, 2026
Merged
Conversation
`Buffer.prototype.slice` is deprecated in favour of `subarray`. From
`@types/node`:
/** @deprecated Use `subarray` instead. */
slice(start?: number, end?: number): Buffer<ArrayBuffer>;
It was deprecated because it does not behave like the
`Uint8Array.prototype.slice` it shadows: the Buffer one returns a view over
the same memory, the TypedArray one copies. `subarray` is the honest name for
the view, and a view is what every one of these call sites wants, since each
one immediately calls `.toString()` on the result.
No behaviour change. Both return a view over the same memory and produce
identical output, so this is a rename at the call site.
The two `result.slice(...)` calls in `Transformer#toString` are left alone.
Those are `String.prototype.slice`, which is not deprecated.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
NullVoxPopuli
approved these changes
Sep 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Buffer.prototype.sliceis deprecated in favour ofsubarray, and this repo uses it in six places. From@types/node:It got deprecated because it does not behave like the
Uint8Array.prototype.sliceit shadows. The Buffer one returns a view over the same memory, the TypedArray one copies.subarrayis the honest name for the view, and a view is what all six call sites want, since every one of them immediately calls.toString()on the result.No behaviour change. Both return a view over the same memory and produce identical output, so this is a rename at the call site:
The two
result.slice(...)calls inTransformer#toStringare untouched. Those areString.prototype.slice, which is not deprecated.tscwas already flagging every one of these, though as a suggestion rather than an error, sopnpm lintwas passing and it was easy to miss. Came up in review on #33, and it does not belong in a BOM fix, so it is here on its own.pnpm testis 70 green.pnpm lintpasseslint:types,lint:packageandlint:published-types.