-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Avoid using deprecated Buffer API on newer Node.js #21
Conversation
This avoids using Buffer constructor API on newer Node.js versions. To achieve that, Buffer.from presence is checked, with validation that it's not the same method as Uint8Array.from. Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
Awesome, thanks! Looks like the tests are failing with the change, and I don't mind adding in I'm curious: is |
@dougwilson, Yeah, the tests were failing because I made a stupid mistype in this PR :-/. Fixed in 7c1855d. Sorry for that.
8eaecc5 doesn't fix this issue as it doesn't load Also, I have concerns with |
Ah, thanks for the explanation! And thanks for your well-written things. I agree with your Re the comment: yea, that was my bad; I missed that in the As a side-note, |
@dougwilson My suggestion would still be to use neither of those and use the approach from 7c1855d instead to remove an extra dependency whatsoever for 0.5.3 (imo the diff of that size doesn't worth a dependency), and to revert this in favor of just |
That said, the current approach in d542fa5 looks fine to me. Just not something that I would have done =). |
@dougwilson Will there be a new release of this package soon that includes this fix please? |
Hi @zoe-mcelderry I apologize; I didn't realize I never released this after merging it. I will make it a priority for when I have time tonight. |
Many thanks! |
Hi @zoe-mcelderry I just released only this change in version 0.5.3. Again, sorry it got forgotten. I'll take a look at the outstanding PRs / issues later today, but just wanted to get this release out for you first 👍 |
Thank you :) |
This avoids using Buffer constructor API on newer Node.js versions.
To achieve that,
Buffer.from
presence is checked, with validation that it's not the same method asUint8Array.from
.The
!number
type-guard for older Node.js versions is excluded and replaced with a comment, asbinary
is always a string there and this looks to be potentially hot code path.Given this module popularity and the fact that old Buffer constructor API was used in a single place, I decided to just feature-detect it in-place instead of pulling in polyfill deps.
Another way would be to just use
Buffer.from
and dovar Buffer = require('safe-buffer')
;Refs:
https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
Tracking: nodejs/node#19079