-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
string_decoder : support typed array or data view #22562
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
Changes from 1 commit
8f14d9c
7505b48
3a25c6e
9057575
62393c0
5fb3198
510ac79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Fixes: #1826
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ decoder = new StringDecoder('utf8'); | |
| assert.strictEqual(decoder.write(Buffer.from('E1', 'hex')), ''); | ||
|
|
||
| // A quick test for lastChar, lastNeed & lastTotal which are undocumented. | ||
| assert(decoder.lastChar.equals(new Uint8Array([0xe1, 0, 0, 0]))); | ||
| assert(decoder.lastChar.equals(Buffer.from([0xe1, 0, 0, 0]))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To elaborate a bit: There's nothing in this change that breaks
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't test cases be added for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was working with the suggestion of this comment here:
I was trying not to use If this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buffer extends Uint8Array, I don't think this changed anything. |
||
| assert.strictEqual(decoder.lastNeed, 2); | ||
| assert.strictEqual(decoder.lastTotal, 3); | ||
|
|
||
|
|
@@ -174,8 +174,8 @@ common.expectsError( | |
| { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| type: TypeError, | ||
| message: 'The "buf" argument must be one of type Buffer, Uint8Array, or' + | ||
| ' ArrayBufferView. Received type object' | ||
| message: 'The "buf" argument must be one of type Buffer, TypedArray,' + | ||
| ' DataView, or ArrayBufferView. Received type object' | ||
| } | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
Uint8Arraybeing removed here?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the suggestion of this comment in #1826, "string_decoder" seems to be on the list
TypedArray/DataViewsupport only. After viewing the fs PR and the child_process, I just gave my best attempt to follow the "idea" to handle string_decode.Please let me know if I misunderstood too much off from the context of the checklist & goals from the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay and somewhat consistent with how we handle it elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BeniCheni , I think broadly we can categorize the changes for these PRs into:
TypedArrays andDataViews wherever onlyBuffers orUint8Arrays were tested earlierliband maybelib/internal)Here, your PR is updating the errors being thrown, but is neither adding test cases nor adding functionality to work with the
TypedArrays orDataViews. Please note, it might well be the case thatstring_decoderalready works for these, but adding test cases is a way of validation for the same. Hope that helps!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏 for the collective reviews. Will analyze & update accordingly.