`Buffer()` without a `new` keyword is going to be hard-deprecated soon
See original GitHub issueRefs: https://github.com/nodejs/node/pull/8169, https://github.com/nodejs/node/pull/7152.
Two options here:
- Use the new Buffer API —
Buffer.alloc()
/Buffer.from()
/Buffer.allocUnsafe()
(requires a shim for v0.10/v0.12 and older v4.x versions prior to v4.5.0). - Use
new Buffer()
for the time being — just add thenew
keyword everywhere. You should manually check that everything is safe in this case, see the links below for more explanation. That might be hard-deprecated at some later point.
More background:
- https://github.com/ChALkeR/notes/blob/master/Lets-fix-Buffer-API.md
- https://github.com/ChALkeR/notes/blob/master/Buffer-knows-everything.md
- https://github.com/nodejs/node/pull/7152#issuecomment-240880317
Quick grep (you should better re-check):
browserify-13.1.0.tgz/test/bare.js:34: ps.stdin.end('console.log(Buffer("ABC"))');
browserify-13.1.0.tgz/test/bare_shebang.js:32: ps.stdin.end('#!/usr/bin/env node\nconsole.log(Buffer("WOO"))');
browserify-13.1.0.tgz/test/global/buffer.js:1:t.equal(Buffer('xyz').toString('base64'), 'eHl6');
browserify-13.1.0.tgz/test/global/buffer.js:2:t.equal(Buffer('eHl6', 'base64').toString(), 'xyz');
browserify-13.1.0.tgz/test/leak.js:46: stream.push('t.equal(Buffer("eHl6", "base64").toString(), "xyz")');
The grep above only includes the lines that call Buffer()
without the new
keyword, if you choose to move to the new API — you should probably also replace new Buffer(…)
calls.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Buffer() without a new keyword is going to be hard-deprecated ...
5.0). Use new Buffer() for the time being — just add the new keyword everywhere. You should manually check that everything is safe...
Read more >Only void function can be called with the "new" keyword
I find a way to shut the typescript compiler up, but this will give up the type check(Do it with your caution). var...
Read more >new operator - JavaScript - MDN Web Docs - Mozilla
When a function is called with the new keyword, the function will be used as a constructor. new will do the following things:....
Read more >The “new” keyword, in far too many languages - Medium
I've written this series of blog posts about the new keyword in many languages, as I feel this is a great common thread...
Read more >Flux (reactor-core 3.5.1)
A Reactive Streams Publisher with rx operators that emits 0 to N elements, and then completes (successfully or with an error).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This really sucks. I feel like node core pulled a fast one here and created so much fucking work for everyone in the ecosystem without thinking things through very carefully.
@spelunk To be fair, “pulling a fast one” would be if node core simply dropped constructor usage without any warning. The warning is there to give people time to migrate.
I honestly believe the only real solution is to fix the deprecations upstream/downstream, otherwise you’re just masking the problem and you will get bitten once the deprecation becomes a removal at some point. At that time, things will probably be even worse because you’ll be scrambling to fix actual broken dependencies.