-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buffer.prototype.slice is incompatible with Uint8Array.prototype.slice; it's documented but tends to cause bugs #28087
Comments
The Node.js buffers existed before There is a simple work around that would work for both, Uint8Array and Buffer: Due to that possibility I do not think that we should change this. |
Depends on what you mean by "deprecated". As @BridgeAR mentions, it's used very extensively in the ecosystem so deprecating it as in "printing warnings" is probably out of the question. Some kind of documentation-only "soft deprecation" in the sense of "don't use this, use that" might be acceptable. You could start by adding a note to doc/api/buffer.md that explains how and why |
As you said, deprecating methods is difficult but compatibility with Uint8Array is worth considering in the long-term perspective. Fortunately, I think, it is easier than deprecating |
PR-URL: nodejs#28101 Refs: nodejs#28087 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Closing now that #28101 has been merged. |
The documentation says
Buffer
has an incompatibility withUint8rray
and I believe it is considered to a bug, or at least tends to cause bugs.https://nodejs.org/api/buffer.html
This incompatibility is problematic when a code expects Uint8Array as a parameter and it distinguishes the semantics of
Uint8Array.prototype.slice()
andUint8Array.prototype.subarray()
.Unfortunately, TypeScript can't help this problem because
function f(b: Uint8Array)
can takeBuffer
without notice:I think this incompatibility should be fixed in the long-term perspective, so firstly I propose to mark
slice()
as deprecated.What do you think of it?
The text was updated successfully, but these errors were encountered: