Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

doc: add description of legacy buf.write() format #5710

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/buffer.markdown
Expand Up @@ -98,6 +98,9 @@ The method will not write partial characters.
len = buf.write('\u00bd + \u00bc = \u00be', 0);
console.log(len + " bytes: " + buf.toString('utf8', 0, len));

For some historical reason, the `encoding` can be placed at other position too
Copy link
Member

Choose a reason for hiding this comment

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

s/some historical reason/historical reasons/

@tjfontaine @trevnorris Is this eligible for merging?

Choose a reason for hiding this comment

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

@bnoordhuis I had a conversation with @isaacs about the fact that were we place the encoding argument varies throughout core. The legacy way of placing encoding actually matches better how it's done elsewhere. And the possibility of un-legacy-ifying the syntax. Isaac, your opinion?

Choose a reason for hiding this comment

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

Either way, the legacy format will actually print a deprecation warning right now, so either we remove the deprecation warning and continue to support it, or it's going to be removed in v1.0 anyways. I don't care either way really. Thoughts?

so that it makes following forms legal: `buf.write(string, [offset], [encoding])`
or `buf.write(string, [encoding], [offset], [length])`.

### buf.toString([encoding], [start], [end])

Expand Down