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.alloc() instead of deprecated new Buffer() in copy-file-sync #380

Merged
merged 1 commit into from Mar 7, 2017

Conversation

manidlou
Copy link
Collaborator

@manidlou manidlou commented Mar 6, 2017

Since new Buffer() is deprecated, https://nodejs.org/api/buffer.html#buffer_new_buffer_size, I updated lib/copy-sync/copy-file-sync.js to use Buffer.alloc() instead of deprecated new Buffer().

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.9%) to 79.521% when pulling 785705b on copy-file-sync-update-Buffer-alloc into e771770 on master.

@manidlou
Copy link
Collaborator Author

manidlou commented Mar 6, 2017

Why coverage decreased by -5.9%?!! 😳. The only thing that is changed is just a word!

Edit

IDK, maybe related to lemurheavy/coveralls-public#463.

@jprichardson
Copy link
Owner

Great idea! The engine field in package.json must be set to at least 4.5.0 as Buffer.alloc didn't exist before it. Please add that change 😄

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 6, 2017

@jprichardson Wasn't aware of that. Isn't that a breaking change?

@jprichardson
Copy link
Owner

@jprichardson Wasn't aware of that. Isn't that a breaking change?

Not strictly - it's more or less tightening the rules, as fs-extra still supports Node v4. Just not pre v4.5.0 - to be extra safe, I'm okay if we do another major bump but may not be necessary.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.9%) to 79.521% when pulling 6bff133 on copy-file-sync-update-Buffer-alloc into e771770 on master.

…nc, add engines field to package.json to specify min node v4.5.0
@manidlou manidlou force-pushed the copy-file-sync-update-Buffer-alloc branch from 6bff133 to 5597bd5 Compare March 7, 2017 01:24
@coveralls
Copy link

Coverage Status

Coverage remained the same at 79.521% when pulling 5597bd5 on copy-file-sync-update-Buffer-alloc into e06440b on master.

@manidlou
Copy link
Collaborator Author

manidlou commented Mar 7, 2017

I rebased this on top of master.

@jprichardson jprichardson merged commit 9bef553 into master Mar 7, 2017
@jprichardson
Copy link
Owner

Thanks @manidlou!

@manidlou
Copy link
Collaborator Author

manidlou commented Mar 7, 2017

My pleasure 😄!

@manidlou manidlou deleted the copy-file-sync-update-Buffer-alloc branch March 7, 2017 08:59
@dr-dimitru
Copy link
Contributor

Hello @manidlou ,

I guess I'm nine days late... But why don't we keep backward compatibility and use Buffer.alloc only when it's exists, otherwise fallback to new Buffer constructor?

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 15, 2017

@dr-dimitru Actually, this change was reverted as a hotfix for v2.1.1. I'm thinking about some kind of fallback solution for future releases.

@dr-dimitru
Copy link
Contributor

dr-dimitru commented Mar 15, 2017

Hi @RyanZim ,

Thank you, good to know. And I'm better to read CHANGELOG more carefully.
I believe same should be done for move-sync.

This is how we use it on our packages (for .from() method):

if (typeof Buffer.from === 'function') {
  try {
    // Node 4.4.* Buffer.from already exists, but throws error
    buff = Buffer.from(body, 'base64');
  } catch (_error) {
    buff = new Buffer(body, 'base64');
  }
} else {
  buff = new Buffer(body, 'base64');
}

I can send a PR if you don't mind and agree with suggested code

@manidlou
Copy link
Collaborator Author

Sorry, I've been so busy. I also agree with providing some kind of fallback solution for this.

@RyanZim
Copy link
Collaborator

RyanZim commented Mar 15, 2017

@dr-dimitru I also fixed moveSync in v2.1.1.

Thanks for telling me about Buffer.from in v4.4.x; wasn't aware of that.

I'm gonna try to open an issue later tonight to get some insight/discussion on this.

@dr-dimitru
Copy link
Contributor

dr-dimitru commented Mar 15, 2017

@RyanZim Thank you, keep me updated.

The code-sample above is just an example, same applies to Buffer.alloc too, and other new methods

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.

None yet

5 participants