Skip to content
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

always use Buffer.byteLength to determine length #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pirxpilot
Copy link

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
Copy link
Member

@UlisesGascon UlisesGascon left a comment

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
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.

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.

2 participants