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: add Buffer#subarray() and add note about Uint8Array#slice() #28101

Closed
wants to merge 6 commits into from

Conversation

gfx
Copy link
Contributor

@gfx gfx commented Jun 6, 2019

refs: #28087

  • Added document for Buffer#subarray(); its content is just copied from #slice()
  • Changed document for Buffer#slice() because of its incompatibility with its superclass's method, and also added how to use Uint8Array.prototype.slice() to get a copy of slice
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 Jun 6, 2019
@mscdex
Copy link
Contributor

mscdex commented Jun 6, 2019

I don't think we need to document inherited methods like subarray().

If anything, only the new note should be added to the description for slice().

@gfx
Copy link
Contributor Author

gfx commented Jun 7, 2019

@mscdex

I don't think we need to document inherited methods like subarray().

Really?

There are lots of methods and properties in the doc, directly inherited from Uint8Array, for example:

  • buf[i]
  • buf.buffer
  • buf.byteOffset
  • buf.length
  • buf.entries()
  • buf.keys()
  • buf.values()

I think #subarray() is also a method to be known, which is compatible with Uint8Array.

@mscdex
Copy link
Contributor

mscdex commented Jun 7, 2019

Right, I don't agree those need to be there either.

IMO there is no need to duplicate documentation (already available at places like MDN) for those properties/methods unless there is some behavioral/semantic difference with node's implementation. Making it clear that Buffer inherits from Uint8Array and providing a link to documentation for the latter should be sufficient really.

Even within node's own documentation we generally don't duplicate between similar/super objects (e.g. tls.TLSSocket does not show everything inherited from net.Socket).

@sam-github
Copy link
Contributor

#28101 (comment) makes sense to me. I wonder, do our docs predate Buffer being derived from Uint8Array?

@mscdex
Copy link
Contributor

mscdex commented Jun 8, 2019

do our docs predate Buffer being derived from Uint8Array?

Definitely.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s a good change, because it ultimately encourages using a standardized TypedArray method over our non-standard different-behaviour override of another TypedArray method.

doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Show resolved Hide resolved
gfx and others added 2 commits June 10, 2019 15:17
Co-Authored-By: Anna Henningsen <github@addaleax.net>
Co-Authored-By: Anna Henningsen <github@addaleax.net>
@gfx
Copy link
Contributor Author

gfx commented Jun 10, 2019

Applied suggested changes!

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 10, 2019
@addaleax
Copy link
Member

I’ll land this tomorrow if there are no objections to that.

doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
doc/api/buffer.md Outdated Show resolved Hide resolved
gfx and others added 3 commits June 11, 2019 09:36
Co-Authored-By: Rich Trott <rtrott@gmail.com>
Co-Authored-By: Rich Trott <rtrott@gmail.com>
Co-Authored-By: Rich Trott <rtrott@gmail.com>
@gfx
Copy link
Contributor Author

gfx commented Jun 11, 2019

Thanks, @Trott !

@Trott
Copy link
Member

Trott commented Jun 11, 2019

@Trott
Copy link
Member

Trott commented Jun 13, 2019

Landed in ee16787

@Trott Trott closed this Jun 13, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Jun 13, 2019
PR-URL: nodejs#28101
Refs: nodejs#28087
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@gfx gfx deleted the doc_buffer_subarray_and_slice branch June 13, 2019 04:01
BridgeAR pushed a commit that referenced this pull request Jun 17, 2019
PR-URL: #28101
Refs: #28087
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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.

7 participants