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

Use Buffer.(from|alloc) instead of deprecated Buffer API #46

Closed
wants to merge 1 commit into from

Conversation

ChALkeR
Copy link
Contributor

@ChALkeR ChALkeR commented Mar 21, 2018

This also includes a dependnecy on a polyfill targeting older Node.js versions where Buffer.alloc() and Buffer.from() API is not implemented (Node.js < 4.5.0 and some 5.x versions).

This is mostly a line-to-line change, though in some cases, minor code simplification was done, e.g.

var version = new Buffer(1);
version.writeUInt8(1, 0);

was transformed into

var version = Buffer.from([1]);

Ref: nodejs/node#19079
Ref: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
Ref: https://nodejs.org/api/buffer.html#buffer_class_buffer
Ref: https://github.com/ChALkeR/safer-buffer/blob/master/Porting-Buffer.md
Fixes: #45

Note that this does not completely solve the problem yet, for a complete solution, asn1 (a dependency) should also receive this fix (see below for that one).

But fixing the API usage in this package is still required, and a significant portion of tests pass without ever hitting the deprecated Buffer API in asn1 dependency.

This also includes a dependnecy on a polyfill targeting older Node.js
versions where Buffer.alloc() and Buffer.from() API is not implemented
(Node.js < 4.5.0 and some 5.x versions).

Ref: nodejs/node#19079
Ref: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
Ref: https://nodejs.org/api/buffer.html#buffer_class_buffer
Ref: https://github.com/ChALkeR/safer-buffer/blob/master/Porting-Buffer.md
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Mar 21, 2018

asn1 fix in TritonDataCenter/node-asn1#30.

@BYK
Copy link

BYK commented May 25, 2018

@arekinath would be great if you can merge this and release a new version as this is blocking Yarn from being Node 10 compatible.

We can use the fork but that's less than ideal.

@ChALkeR
Copy link
Contributor Author

ChALkeR commented May 31, 2018

/cc @cjihrig and @Trott perhaps?

@stevestock
Copy link

@arekinath

@shahkashani
Copy link

Bump <3 Would love to get this (and yarnpkg/yarn#5477) fixed!

joyent-automation pushed a commit that referenced this pull request Jun 5, 2018
Reviewed by: Alex Wilson <alex.wilson@joyent.com>
Reviewed by: Cody Peter Mello <cody.mello@joyent.com>
@arekinath
Copy link
Contributor

Merged as 175758a, released in 1.14.2

@arekinath arekinath closed this Jun 5, 2018
@ChALkeR
Copy link
Contributor Author

ChALkeR commented Jun 5, 2018

@arekinath Thanks!

@BYK
Copy link

BYK commented Jun 7, 2018

@arekinath thanks a lot for the merge and release! It would be ideal if we can propagate this fix all the way to upstream. There are a few more fixes on joyent repos:

Do you think you can help with those too?

And since sshpk depends on asn1, we'd need to make another patch and release here once that PR is merged and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buffer constructor runtime deprecation - this package emits a warning on Node 10
5 participants