Skip to content

always use Buffer.byteLength to determine length - #35

Closed
pirxpilot wants to merge 1 commit into
jshttp:masterfrom
pirxpilot:improve-byte-length-usage
Closed

pirxpilot wants to merge 1 commit into
jshttp:masterfrom
pirxpilot:improve-byte-length-usage

Conversation

@pirxpilot

Copy link
Copy Markdown

there is no need to check the entity type because Buffer.byteLength works correctly for both String and Buffer
utf8 is the default encoding when entity is a String

this change also make the module compatible with TypedArray entities

see:
https://nodejs.org/api/buffer.html#static-method-bufferbytelengthstring-encoding

there is no need to check the entity type because `Buffer.byteLength`
works correctly for both `String` and `Buffer`
`utf8` is the default encoding when entity is a `String`

this change also make the module compatible with `TypedArray` entities

see:
https://nodejs.org/api/buffer.html#static-method-bufferbytelengthstring-encoding

@UlisesGascon UlisesGascon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pirxpilot for creating this PR! :)

Currently we support Node.js super legacy versions, like Node@0.8 and this refactor might not work for that versions (ref) buffer support was added "recently".

But this change can work 💯 for the next major 👍

@pirxpilot

Copy link
Copy Markdown
Author

Thanks. Makes sense.
In case folks need that info Buffer.byteLength in its modern form has been implemented in node 6.0
There might be a subtle issue with the wrong length being used when etag module gets passed TypedArray but probably with minuscule real world impact.

@blakeembrey

Copy link
Copy Markdown
Member

Thank you for the PR and sorry it's taken a couple of years to prepare the next major. This has been accomplished in #65 and #69. The latter will support any TypedArray as you mentioned in the PR body, it's a great idea. The existing major will continue to not support these since there's an explicit Buffer.isBuffer check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants