-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
buffer: backport new buffer constructor APIs #5763
Conversation
return fromString(arg, encoding); | ||
if (typeof encodingOrOffset === 'string') { | ||
throw new Error( | ||
'If encoding is specified then the first argument must be a string' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this particular bit is a semver-major change that was landed in master. I included it in the backport to ensure that the new api behavior in master would match what is backported. I can pull this new throw back out, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah let's keep this purely additive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, pulled that throw back out and another. It's still not 100% "purely additive" in that it includes the change to fill('')
to ensure it zero-fills as opposed to doing nothing.
@nodejs/collaborators ... ping |
Don't remember the discussion about back porting to v5.x, but assuming we did. LGTM. |
Adding this to CTC Agenda for 2016-03-23 just to make sure there are no @nodejs/ctc objections to backporting the API changes to v5 and v4 and the |
Discussion on the CTC was to go ahead with in v5 but to hold off on backporting further back. |
@nodejs/ctc @nodejs/collaborators ... have one LGTM on this and no objections from CTC. However, it would be good to get some additional sign off. I'll give it 24 more hours for review then land tomorrow. |
This backports the new `Buffer.alloc()`, `Buffer.allocUnsafe()`, and `Buffer.from()` APIs for v5. Also included in this backport is the change that allows fill('') to zero-fill (as opposed to doing nothing) and the additional `byteOffset` and `length` arguments for `Buffer(arrayBuffer)` and `Buffer.from(arrayBuffer)`. This backport includes the new test cases. This backport *does not* update all of the internal uses of the existing `Buffer()` constructor. This backport also *does not* include the soft deprecation of the existing `Buffer()` constructor.
6c5bc34
to
c04c7bd
Compare
CI is green except for one unrelated failure. |
This backports the new `Buffer.alloc()`, `Buffer.allocUnsafe()`, and `Buffer.from()` APIs for v5. Also included in this backport is the change that allows fill('') to zero-fill (as opposed to doing nothing) and the additional `byteOffset` and `length` arguments for `Buffer(arrayBuffer)` and `Buffer.from(arrayBuffer)`. This backport includes the new test cases. This backport *does not* update all of the internal uses of the existing `Buffer()` constructor. This backport also *does not* include the soft deprecation of the existing `Buffer()` constructor. PR-URL: #5763 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Landed in v5.x in c1534e7 |
Notable changes: * buffer: * make byteLength work with ArrayBuffer & DataView (Jackson Tian) [#5255](#5255) * backport --zero-fill-buffers command line option (James M Snell) [#5744](#5744) * backport new buffer constructor APIs (James M Snell) [#5763](#5763) * add swap16() and swap32() methods (James M Snell) [#5724](#5724) * fs: add the fs.mkdtemp() function. (Florian MARGAINE) [#5333](#5333) * net: emit host in lookup event (HUANG Wei) [#5598](#5598) * node: --no-browser-globals configure flag (Fedor Indutny) [#5853](#5853) * npm: Upgrade to v3.8.3. (Forrest L Norvell) * repl: support standalone blocks (Prince J Wesley) [#5581](#5581) * src: override v8 thread defaults using cli options (Tom Gallacher) [#4344](#4344)
Notable changes: * buffer: * make byteLength work with ArrayBuffer & DataView (Jackson Tian) [#5255](#5255) * backport --zero-fill-buffers command line option (James M Snell) [#5744](#5744) * backport new buffer constructor APIs (James M Snell) [#5763](#5763) * add swap16() and swap32() methods (James M Snell) [#5724](#5724) * fs: add the fs.mkdtemp() function. (Florian MARGAINE) [#5333](#5333) * net: emit host in lookup event (HUANG Wei) [#5598](#5598) * node: --no-browser-globals configure flag (Fedor Indutny) [#5853](#5853) * npm: Upgrade to v3.8.3. Fixes a security flaw in the use of authentication tokens in HTTP requests that would allow an attacker to set up a server that could collect tokens from users of the command-line interface. Authentication tokens have previously been sent with every request made by the CLI for logged-in users, regardless of the destination of the request. This update fixes this by only including those tokens for requests made against the registry or registries used for the current install. (Forrest L Norvell) [npm#6](npm#6) * repl: support standalone blocks (Prince J Wesley) [#5581](#5581) * src: override v8 thread defaults using cli options (Tom Gallacher) [#4344](#4344)
Notable changes: * buffer: * make byteLength work with ArrayBuffer & DataView (Jackson Tian) [#5255](#5255) * backport --zero-fill-buffers command line option (James M Snell) [#5744](#5744) * backport new buffer constructor APIs (James M Snell) [#5763](#5763) * add swap16() and swap32() methods (James M Snell) [#5724](#5724) * fs: add the fs.mkdtemp() function. (Florian MARGAINE) [#5333](#5333) * net: emit host in lookup event (HUANG Wei) [#5598](#5598) * node: --no-browser-globals configure flag (Fedor Indutny) [#5853](#5853) * npm: Upgrade to v3.8.3. Fixes a security flaw in the use of authentication tokens in HTTP requests that would allow an attacker to set up a server that could collect tokens from users of the command-line interface. Authentication tokens have previously been sent with every request made by the CLI for logged-in users, regardless of the destination of the request. This update fixes this by only including those tokens for requests made against the registry or registries used for the current install. (Forrest L Norvell) [npm#6](npm#6) * repl: support standalone blocks (Prince J Wesley) [#5581](#5581) * src: override v8 thread defaults using cli options (Tom Gallacher) [#4344](#4344)
Notable changes: * buffer: * make byteLength work with ArrayBuffer & DataView (Jackson Tian) [#5255](#5255) * backport --zero-fill-buffers command line option (James M Snell) [#5744](#5744) * backport new buffer constructor APIs (James M Snell) [#5763](#5763) * add swap16() and swap32() methods (James M Snell) [#5724](#5724) * fs: add the fs.mkdtemp() function. (Florian MARGAINE) [#5333](#5333) * net: emit host in lookup event (HUANG Wei) [#5598](#5598) * node: --no-browser-globals configure flag (Fedor Indutny) [#5853](#5853) * npm: Upgrade to v3.8.3. Fixes a security flaw in the use of authentication tokens in HTTP requests that would allow an attacker to set up a server that could collect tokens from users of the command-line interface. Authentication tokens have previously been sent with every request made by the CLI for logged-in users, regardless of the destination of the request. This update fixes this by only including those tokens for requests made against the registry or registries used for the current install. (Forrest L Norvell) [npm#6](npm#6) * repl: support standalone blocks (Prince J Wesley) [#5581](#5581) * src: override v8 thread defaults using cli options (Tom Gallacher) [#4344](#4344) PR-URL: #5970
## Buffers and ES6 iteration | ||
|
||
Buffers can be iterated over using the ECMAScript 2015 (ES6) `for..of` syntax: | ||
|
||
```js | ||
const buf = new Buffer([1, 2, 3]); | ||
const buf = Buffer(.from[1, 2, 3]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be a typo; should be Buffer.from([1, 2, 3]);
??
Yeah, as far as I know #5833 hasn't been backported yet to v5. I'll open a PR for that soon |
@jasnell Any chance we can also backport to Node.js v4? Once v0.10 and and v0.12 are unsupported at the end of the year, it would be nice to start advising people to use only the new Buffer APIs ( If we have support in v4, that would make shims like |
Pull Request check-list
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
buffer
Description of change
This backports the new
Buffer.alloc()
,Buffer.allocUnsafe()
, andBuffer.from()
APIs for v5.Also included in this backport is the change that allows fill('') to zero-fill (as opposed to doing nothing) and the additional
byteOffset
andlength
arguments forBuffer(arrayBuffer)
andBuffer.from(arrayBuffer)
.This backport includes the new test cases.
This backport does not update all of the internal uses of the existing
Buffer()
constructor.This backport also does not include the soft deprecation of the existing
Buffer()
constructor.Refs: #5744
/cc: @Fishrock123 @trevnorris @nodejs/ctc @nodejs/lts