@@ -827,8 +827,9 @@ A `TypeError` will be thrown if `size` is not a number.
827827The ` Buffer ` module pre-allocates an internal ` Buffer ` instance of
828828size [ ` Buffer.poolSize ` ] [ ] that is used as a pool for the fast allocation of new
829829` Buffer ` instances created using [ ` Buffer.allocUnsafe() ` ] [ ] , [ ` Buffer.from(array) ` ] [ ] ,
830- [ ` Buffer.from(string) ` ] [ ] , and [ ` Buffer.concat() ` ] [ ] only when ` size ` is less than
831- ` Buffer.poolSize >>> 1 ` (floor of [ ` Buffer.poolSize ` ] [ ] divided by two).
830+ [ ` Buffer.from(string) ` ] [ ] , [ ` Buffer.of(...items) ` ] [ ] , and [ ` Buffer.concat() ` ] [ ]
831+ only when ` size ` is less than ` Buffer.poolSize >>> 1 ` (floor of [ ` Buffer.poolSize ` ] [ ]
832+ divided by two).
832833
833834Use of this pre-allocated internal memory pool is a key difference between
834835calling ` Buffer.alloc(size, fill) ` vs. ` Buffer.allocUnsafe(size).fill(fill) ` .
@@ -1419,6 +1420,36 @@ appropriate for `Buffer.from()` variants.
14191420[ ` Buffer.from(string) ` ] [ ] may also use the internal ` Buffer ` pool like
14201421[ ` Buffer.allocUnsafe() ` ] [ ] does.
14211422
1423+ ### Static method: ` Buffer.of(...items) `
1424+
1425+ <!-- YAML
1426+ added: v5.10.0
1427+ -->
1428+
1429+ * ` ...items ` {integer} A sequence of numeric byte values (0–255).
1430+ * Returns: {Buffer}
1431+
1432+ Creates a new ` Buffer ` from the given numeric arguments.
1433+
1434+ This is equivalent to the standard ` TypedArray.of() ` factory, but returns a
1435+ ` Buffer ` instead of a generic ` Uint8Array ` . Each argument provides the value of
1436+ the corresponding byte in the resulting buffer.
1437+
1438+ ``` mjs
1439+ import { Buffer } from ' node:buffer' ;
1440+
1441+ const buf = Buffer .of (0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 );
1442+ ```
1443+
1444+ ``` cjs
1445+ const { Buffer } = require (' node:buffer' );
1446+
1447+ const buf = Buffer .of (0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 );
1448+ ```
1449+
1450+ [ ` Buffer.of(...items) ` ] [ ] may also use the internal ` Buffer ` pool like
1451+ [ ` Buffer.allocUnsafe() ` ] [ ] does.
1452+
14221453### Static method: ` Buffer.isBuffer(obj) `
14231454
14241455<!-- YAML
@@ -5461,8 +5492,9 @@ to one of these new APIs._
54615492 potentially sensitive.
54625493
54635494` Buffer ` instances returned by [ ` Buffer.allocUnsafe() ` ] [ ] , [ ` Buffer.from(string) ` ] [ ] ,
5464- [ ` Buffer.concat() ` ] [ ] and [ ` Buffer.from(array) ` ] [ ] _ may_ be allocated off a shared
5465- internal memory pool if ` size ` is less than or equal to half [ ` Buffer.poolSize ` ] [ ] .
5495+ [ ` Buffer.of(...items) ` ] [ ] , [ ` Buffer.concat() ` ] [ ] , and [ ` Buffer.from(array) ` ] [ ]
5496+ _ may_ be allocated off a shared internal memory pool if ` size ` is less than or
5497+ equal to half [ ` Buffer.poolSize ` ] [ ] .
54665498Instances returned by [ ` Buffer.allocUnsafeSlow() ` ] [ ] _ never_ use the shared internal
54675499memory pool.
54685500
@@ -5515,6 +5547,7 @@ introducing security vulnerabilities into an application.
55155547[ `Buffer.from(arrayBuf)` ] : #static-method-bufferfromarraybuffer-byteoffset-length
55165548[ `Buffer.from(buffer)` ] : #static-method-bufferfrombuffer
55175549[ `Buffer.from(string)` ] : #static-method-bufferfromstring-encoding
5550+ [ `Buffer.of(...items)` ] : #static-method-bufferofitems
55185551[ `Buffer.poolSize` ] : #bufferpoolsize
55195552[ `ERR_INVALID_BUFFER_SIZE` ] : errors.md#err_invalid_buffer_size
55205553[ `ERR_OUT_OF_RANGE` ] : errors.md#err_out_of_range
0 commit comments