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

doc: clarify length param in buffer.write #32119

Closed

Conversation

HarshithaKP
Copy link
Member

buffer.write documentation has an incaccuracy w.r.t the length parameter:
It says default number of bytes written is buf.length - offset. Change it to:
If the buffer has sufficient space from the offset, the string is written upto length.
If the buffer is short in space, only buf.length - offset bytes are written.

proof:

#node
> let buf = Buffer.alloc(10)
undefined
> buf
<Buffer 00 00 00 00 00 00 00 00 00 00>
> buf.write(‘abcd’, 3)
4
> buf
<Buffer 00 00 00 61 62 63 64 00 00 00>
> buf = Buffer.alloc(10)
<Buffer 00 00 00 00 00 00 00 00 00 00>
> buf.write(‘abcd’, 9)
1
> buf
<Buffer 00 00 00 00 00 00 00 00 00 61>
>

Refs : #32104 (comment)

Thanks to @addaleax for her suggestion in the above comment, that lead to this finding.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations. labels Mar 6, 2020
HarshithaKP added a commit to HarshithaKP/node that referenced this pull request Mar 6, 2020
Make sure longer strings are written up to the buffer end

Refs: nodejs#32119
doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
addaleax pushed a commit that referenced this pull request Mar 12, 2020
Make sure longer strings are written up to the buffer end

Refs: #32119

PR-URL: #32123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@addaleax
Copy link
Member

@HarshithaKP There are conflicts here, can you rebase against master?

`buffer.write` documentation has an incaccuracy w.r.t the `length`
parameter: It says default number of bytes written is
`buf.length - offset`. Change it to:
If the buffer has sufficient space from the offset, the string is
written upto `length`.
If the buffer is short in space, only `buf.length - offset` bytes are
written.

Refs : nodejs#32104 (comment)
@HarshithaKP
Copy link
Member Author

@addaleax, thanks. Rebased it. PTAL.

doc/api/buffer.md Outdated Show resolved Hide resolved
BridgeAR pushed a commit that referenced this pull request Mar 17, 2020
Make sure longer strings are written up to the buffer end

Refs: #32119

PR-URL: #32123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Mar 24, 2020
Make sure longer strings are written up to the buffer end

Refs: #32119

PR-URL: #32123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
addaleax pushed a commit that referenced this pull request Apr 5, 2020
`buffer.write` documentation has an incaccuracy w.r.t the `length`
parameter: It says default number of bytes written is
`buf.length - offset`. Change it to:
If the buffer has sufficient space from the offset, the string is
written upto `length`.
If the buffer is short in space, only `buf.length - offset` bytes are
written.

Refs: #32104 (comment)

PR-URL: #32119
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@addaleax
Copy link
Member

addaleax commented Apr 5, 2020

Landed in d03d9a0

@addaleax addaleax closed this Apr 5, 2020
BethGriggs pushed a commit that referenced this pull request Apr 7, 2020
`buffer.write` documentation has an incaccuracy w.r.t the `length`
parameter: It says default number of bytes written is
`buf.length - offset`. Change it to:
If the buffer has sufficient space from the offset, the string is
written upto `length`.
If the buffer is short in space, only `buf.length - offset` bytes are
written.

Refs: #32104 (comment)

PR-URL: #32119
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Apr 12, 2020
`buffer.write` documentation has an incaccuracy w.r.t the `length`
parameter: It says default number of bytes written is
`buf.length - offset`. Change it to:
If the buffer has sufficient space from the offset, the string is
written upto `length`.
If the buffer is short in space, only `buf.length - offset` bytes are
written.

Refs: #32104 (comment)

PR-URL: #32119
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Apr 22, 2020
Make sure longer strings are written up to the buffer end

Refs: #32119

PR-URL: #32123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
targos pushed a commit that referenced this pull request Apr 22, 2020
`buffer.write` documentation has an incaccuracy w.r.t the `length`
parameter: It says default number of bytes written is
`buf.length - offset`. Change it to:
If the buffer has sufficient space from the offset, the string is
written upto `length`.
If the buffer is short in space, only `buf.length - offset` bytes are
written.

Refs: #32104 (comment)

PR-URL: #32119
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants