Skip to content

Commit

Permalink
doc: fix error notes in Buffer.from() variants
Browse files Browse the repository at this point in the history
Make notes about `TypeError` conditions in `Buffer.from()` variants
more accurate.

PR-URL: #27030
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
  • Loading branch information
vsemozhetbyt authored and BethGriggs committed Apr 9, 2019
1 parent e18a0e8 commit c3d573d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ Allocates a new `Buffer` using an `array` of octets.
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

A `TypeError` will be thrown if `array` is not an `Array`.
A `TypeError` will be thrown if `array` is not an `Array` or other type
appropriate for `Buffer.from()` variants.

### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
<!-- YAML
Expand Down Expand Up @@ -836,7 +837,7 @@ console.log(buf.length);
```

A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a
[`SharedArrayBuffer`].
[`SharedArrayBuffer`] or other type appropriate for `Buffer.from()` variants.

### Class Method: Buffer.from(buffer)
<!-- YAML
Expand All @@ -860,7 +861,8 @@ console.log(buf2.toString());
// Prints: buffer
```

A `TypeError` will be thrown if `buffer` is not a `Buffer`.
A `TypeError` will be thrown if `buffer` is not a `Buffer` or other type
appropriate for `Buffer.from()` variants.

### Class Method: Buffer.from(object[, offsetOrEncoding[, length]])
<!-- YAML
Expand Down Expand Up @@ -896,6 +898,9 @@ const buf = Buffer.from(new Foo(), 'utf8');
// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>
```

A `TypeError` will be thrown if `object` has not mentioned methods or is not of
other type appropriate for `Buffer.from()` variants.

### Class Method: Buffer.from(string[, encoding])
<!-- YAML
added: v5.10.0
Expand All @@ -919,7 +924,8 @@ console.log(buf1.toString('ascii'));
// Prints: this is a tC)st
```

A `TypeError` will be thrown if `string` is not a string.
A `TypeError` will be thrown if `string` is not a string or other type
appropriate for `Buffer.from()` variants.

### Class Method: Buffer.isBuffer(obj)
<!-- YAML
Expand Down

0 comments on commit c3d573d

Please sign in to comment.