• Home
  • Raw
  • Download

Lines Matching +full:no +full:- +full:console

3 <!--introduced_in=v0.1.90-->
5 > Stability: 2 - Stable
7 <!-- source_link=lib/buffer.js -->
9 `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
20 // Creates a zero-filled Buffer of length 10.
39 const buf5 = Buffer.from([257, 257.5, -255, '1']);
41 // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
46 // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
51 <!-- YAML
53 - version: v14.18.0
54 pr-url: https://github.com/nodejs/node/pull/36952
56 - version: v6.4.0
57 pr-url: https://github.com/nodejs/node/pull/7111
59 - version: v5.0.0
60 pr-url: https://github.com/nodejs/node/pull/2859
62 -->
65 specified. If no character encoding is specified, UTF-8 will be used as the
71 console.log(buf.toString('hex'));
73 console.log(buf.toString('base64'));
76 console.log(Buffer.from('fhqwhgads', 'utf8'));
78 console.log(Buffer.from('fhqwhgads', 'utf16le'));
84 * `'utf8'`: Multi-byte encoded Unicode characters. Many web pages and other
85 document formats use [UTF-8][]. This is the default character encoding.
87 valid UTF-8 data, the Unicode replacement character `U+FFFD` � will be used
90 * `'utf16le'`: Multi-byte encoded Unicode characters. Unlike `'utf8'`, each
92 Node.js only supports the [little-endian][endianness] variant of [UTF-16][].
94 * `'latin1'`: Latin-1 stands for [ISO-8859-1][]. This character encoding only
102 Node.js also supports the following binary-to-text encodings. For
103 binary-to-text encodings, the naming convention is reversed: Converting a
110 tabs, and new lines contained within the base64-encoded string are ignored.
114 encoding will also correctly accept regular base64-encoded strings. When
123 * `'ascii'`: For 7-bit [ASCII][] data only. When encoding a string into a
127 Generally, there should be no reason to use this encoding, as `'utf8'`
128 (or, if the data is known to always be ASCII-only, `'latin1'`) will be a
129 better choice when encoding or decoding ASCII-only text. It is only provided
135 between strings and `Buffer`s, typically `'utf-8'` is the right choice.
137 * `'ucs2'`: Alias of `'utf16le'`. UCS-2 used to refer to a variant of UTF-16
143 // Prints <Buffer 1a>, data truncated when first non-hexadecimal value
154 both `'latin1'` and `'ISO-8859-1'` to `'win-1252'`. This means that while doing
157 `'win-1252'`-encoded data, and using `'latin1'` encoding may incorrectly decode
161 <!-- YAML
163 - version: v3.0.0
164 pr-url: https://github.com/nodejs/node/pull/2002
166 -->
194 console.log(uint32array);
209 console.log(uint16array);
231 console.log(buf1);
233 console.log(buf2);
238 console.log(buf1);
240 console.log(buf2);
252 console.log(buf.length);
279 console.log(b);
291 <!-- YAML
293 -->
295 > Stability: 1 - Experimental
301 <!-- YAML
303 -->
311 * `type` {string} The Blob content-type. The intent is for `type` to convey
312 the MIME media type of the data, however no validation of the type format
323 <!-- YAML
325 -->
333 <!-- YAML
335 -->
340 <!-- YAML
342 -->
346 * `type` {string} The content-type for the new `Blob`
352 <!-- YAML
354 -->
358 Returns a promise that resolves the contents of the `Blob` decoded as a UTF-8
362 <!-- YAML
364 -->
368 The content-type of the `Blob`.
386 console.log(await data.arrayBuffer());
392 console.log(await data.arrayBuffer());
400 data.text().then(console.log);
409 <!-- YAML
412 - version: v10.0.0
413 pr-url: https://github.com/nodejs/node/pull/18129
414 description: Attempting to fill a non-zero length buffer with a zero length
416 - version: v10.0.0
417 pr-url: https://github.com/nodejs/node/pull/17427
420 - version: v8.9.3
421 pr-url: https://github.com/nodejs/node/pull/17428
423 zero-filled buffer.
424 -->
427 * `fill` {string|Buffer|Uint8Array|integer} A value to pre-fill the new `Buffer`
433 `Buffer` will be zero-filled.
438 console.log(buf);
452 console.log(buf);
462 console.log(buf);
474 <!-- YAML
477 - version: v7.0.0
478 pr-url: https://github.com/nodejs/node/pull/7079
480 -->
496 console.log(buf);
501 console.log(buf);
507 The `Buffer` module pre-allocates an internal `Buffer` instance of
514 Use of this pre-allocated internal memory pool is a key difference between
523 <!-- YAML
525 -->
531 is thrown. A zero-length `Buffer` is created if `size` is 0.
539 allocations under 4KB are sliced from a single pre-allocated `Buffer`. This
547 to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
571 <!-- YAML
574 - version: v7.0.0
575 pr-url: https://github.com/nodejs/node/pull/8946
577 - version: v5.10.0
578 pr-url: https://github.com/nodejs/node/pull/5255
581 -->
594 For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
601 console.log(`${str}: ${str.length} characters, ` +
611 <!-- YAML
614 - version: v8.0.0
615 pr-url: https://github.com/nodejs/node/pull/10236
617 -->
621 * Returns: {integer} Either `-1`, `0`, or `1`, depending on the result of the
633 console.log(arr.sort(Buffer.compare));
639 <!-- YAML
642 - version: v8.0.0
643 pr-url: https://github.com/nodejs/node/pull/10236
645 -->
656 If the list has no items, or if the `totalLength` is 0, then a new zero-length
674 console.log(totalLength);
679 console.log(bufA);
681 console.log(bufA.length);
689 <!-- YAML
691 -->
699 // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
710 <!-- YAML
712 -->
719 **Default:** `arrayBuffer.byteLength - byteOffset`.
735 console.log(buf);
741 console.log(buf);
752 console.log(buf.length);
768 console.log(arrA.buffer === arrB.buffer); // true
771 console.log(buf);
776 <!-- YAML
778 -->
791 console.log(buf1.toString());
793 console.log(buf2.toString());
801 <!-- YAML
803 -->
806 * `offsetOrEncoding` {integer|string} A byte-offset or encoding.
835 <!-- YAML
837 -->
849 console.log(buf1.toString());
851 console.log(buf2.toString());
853 console.log(buf1.toString('latin1'));
861 <!-- YAML
863 -->
879 <!-- YAML
881 -->
890 console.log(Buffer.isEncoding('utf-8'));
893 console.log(Buffer.isEncoding('hex'));
896 console.log(Buffer.isEncoding('utf/8'));
899 console.log(Buffer.isEncoding(''));
904 <!-- YAML
906 -->
910 This is the size (in bytes) of pre-allocated internal `Buffer` instances used
921 This operator is inherited from `Uint8Array`, so its behavior on out-of-bounds
929 // (This only works for ASCII-only strings. In general, one should use
939 console.log(buf.toString('utf8'));
955 console.log(buffer.buffer === arrayBuffer);
985 <!-- YAML
988 - version: v8.0.0
989 pr-url: https://github.com/nodejs/node/pull/10236
991 - version: v5.11.0
992 pr-url: https://github.com/nodejs/node/pull/5880
994 -->
1014 * `-1` is returned if `target` should come *after* `buf` when sorted.
1021 console.log(buf1.compare(buf1));
1023 console.log(buf1.compare(buf2));
1024 // Prints: -1
1025 console.log(buf1.compare(buf3));
1026 // Prints: -1
1027 console.log(buf2.compare(buf1));
1029 console.log(buf2.compare(buf3));
1031 console.log([buf1, buf2, buf3].sort(Buffer.compare));
1044 console.log(buf1.compare(buf2, 5, 9, 0, 4));
1046 console.log(buf1.compare(buf2, 0, 6, 4));
1047 // Prints: -1
1048 console.log(buf1.compare(buf2, 5, 6, 5));
1056 <!-- YAML
1058 -->
1091 console.log(buf2.toString('ascii', 0, 25));
1108 console.log(buf.toString());
1113 <!-- YAML
1115 -->
1128 console.log(pair);
1140 <!-- YAML
1143 - version: v8.0.0
1144 pr-url: https://github.com/nodejs/node/pull/10236
1146 -->
1161 console.log(buf1.equals(buf2));
1163 console.log(buf1.equals(buf3));
1168 <!-- YAML
1171 - version: v11.0.0
1172 pr-url: https://github.com/nodejs/node/pull/22969
1174 - version: v10.0.0
1175 pr-url: https://github.com/nodejs/node/pull/18790
1177 - version: v10.0.0
1178 pr-url: https://github.com/nodejs/node/pull/18129
1179 description: Attempting to fill a non-zero length buffer with a zero length
1181 - version: v10.0.0
1182 pr-url: https://github.com/nodejs/node/pull/17427
1185 - version: v5.7.0
1186 pr-url: https://github.com/nodejs/node/pull/4935
1188 -->
1207 console.log(b.toString());
1215 If the final write of a `fill()` operation falls on a multi-byte character,
1219 // Fill a `Buffer` with character that takes up two bytes in UTF-8.
1221 console.log(Buffer.allocUnsafe(5).fill('\u0222'));
1225 If `value` contains invalid characters, it is truncated; if no valid
1231 console.log(buf.fill('a'));
1233 console.log(buf.fill('aazz', 'hex'));
1235 console.log(buf.fill('zz', 'hex'));
1240 <!-- YAML
1242 -->
1251 Equivalent to [`buf.indexOf() !== -1`][`buf.indexOf()`].
1256 console.log(buf.includes('this'));
1258 console.log(buf.includes('is'));
1260 console.log(buf.includes(Buffer.from('a buffer')));
1262 console.log(buf.includes(97));
1264 console.log(buf.includes(Buffer.from('a buffer example')));
1266 console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
1268 console.log(buf.includes('this', 4));
1273 <!-- YAML
1276 - version: v8.0.0
1277 pr-url: https://github.com/nodejs/node/pull/10236
1279 - version:
1280 - v5.7.0
1281 - v4.4.0
1282 pr-url: https://github.com/nodejs/node/pull/4803
1284 is no longer required.
1285 -->
1294 `-1` if `buf` does not contain `value`.
1302 * a number, `value` will be interpreted as an unsigned 8-bit integer
1308 console.log(buf.indexOf('this'));
1310 console.log(buf.indexOf('is'));
1312 console.log(buf.indexOf(Buffer.from('a buffer')));
1314 console.log(buf.indexOf(97));
1316 console.log(buf.indexOf(Buffer.from('a buffer example')));
1317 // Prints: -1
1318 console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
1323 console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
1325 console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
1342 console.log(b.indexOf(99.9));
1343 console.log(b.indexOf(256 + 99));
1347 console.log(b.indexOf('b', undefined));
1348 console.log(b.indexOf('b', {}));
1349 console.log(b.indexOf('b', null));
1350 console.log(b.indexOf('b', []));
1358 <!-- YAML
1360 -->
1370 console.log(key);
1382 <!-- YAML
1385 - version: v8.0.0
1386 pr-url: https://github.com/nodejs/node/pull/10236
1388 -->
1393 `buf.length - 1`.
1398 `-1` if `buf` does not contain `value`.
1406 console.log(buf.lastIndexOf('this'));
1408 console.log(buf.lastIndexOf('buffer'));
1410 console.log(buf.lastIndexOf(Buffer.from('buffer')));
1412 console.log(buf.lastIndexOf(97));
1414 console.log(buf.lastIndexOf(Buffer.from('yolo')));
1415 // Prints: -1
1416 console.log(buf.lastIndexOf('buffer', 5));
1418 console.log(buf.lastIndexOf('buffer', 4));
1419 // Prints: -1
1423 console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
1425 console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
1442 console.log(b.lastIndexOf(99.9));
1443 console.log(b.lastIndexOf(256 + 99));
1447 console.log(b.lastIndexOf('b', undefined));
1448 console.log(b.lastIndexOf('b', {}));
1451 // Prints: -1, equivalent to passing 0.
1452 console.log(b.lastIndexOf('b', null));
1453 console.log(b.lastIndexOf('b', []));
1459 <!-- YAML
1461 -->
1468 // Create a `Buffer` and write a shorter string to it using UTF-8.
1472 console.log(buf.length);
1477 console.log(buf.length);
1482 <!-- YAML
1484 -->
1486 > Stability: 0 - Deprecated: Use [`buf.buffer`][] instead.
1491 <!-- YAML
1493 - v12.0.0
1494 - v10.20.0
1495 -->
1498 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
1501 Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
1507 <!-- YAML
1509 - v12.0.0
1510 - v10.20.0
1511 -->
1514 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
1517 Reads a signed, little-endian 64-bit integer from `buf` at the specified
1524 <!-- YAML
1526 - v12.0.0
1527 - v10.20.0
1529 - version: v14.10.0
1530 pr-url: https://github.com/nodejs/node/pull/34960
1532 -->
1535 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
1538 Reads an unsigned, big-endian 64-bit integer from `buf` at the specified
1546 console.log(buf.readBigUInt64BE(0));
1551 <!-- YAML
1553 - v12.0.0
1554 - v10.20.0
1556 - version:
1557 - v14.10.0
1558 - v12.19.0
1559 pr-url: https://github.com/nodejs/node/pull/34960
1561 -->
1564 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
1567 Reads an unsigned, little-endian 64-bit integer from `buf` at the specified
1575 console.log(buf.readBigUInt64LE(0));
1580 <!-- YAML
1583 - version: v10.0.0
1584 pr-url: https://github.com/nodejs/node/pull/18395
1585 description: Removed `noAssert` and no implicit coercion of the offset
1587 -->
1590 satisfy `0 <= offset <= buf.length - 8`. **Default:** `0`.
1593 Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
1598 console.log(buf.readDoubleBE(0));
1599 // Prints: 8.20788039913184e-304
1603 <!-- YAML
1606 - version: v10.0.0
1607 pr-url: https://github.com/nodejs/node/pull/18395
1608 description: Removed `noAssert` and no implicit coercion of the offset
1610 -->
1613 satisfy `0 <= offset <= buf.length - 8`. **Default:** `0`.
1616 Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
1621 console.log(buf.readDoubleLE(0));
1622 // Prints: 5.447603722011605e-270
1623 console.log(buf.readDoubleLE(1));
1628 <!-- YAML
1631 - version: v10.0.0
1632 pr-url: https://github.com/nodejs/node/pull/18395
1633 description: Removed `noAssert` and no implicit coercion of the offset
1635 -->
1638 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
1641 Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
1646 console.log(buf.readFloatBE(0));
1647 // Prints: 2.387939260590663e-38
1651 <!-- YAML
1654 - version: v10.0.0
1655 pr-url: https://github.com/nodejs/node/pull/18395
1656 description: Removed `noAssert` and no implicit coercion of the offset
1658 -->
1661 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
1664 Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
1669 console.log(buf.readFloatLE(0));
1670 // Prints: 1.539989614439558e-36
1671 console.log(buf.readFloatLE(1));
1676 <!-- YAML
1679 - version: v10.0.0
1680 pr-url: https://github.com/nodejs/node/pull/18395
1681 description: Removed `noAssert` and no implicit coercion of the offset
1683 -->
1686 satisfy `0 <= offset <= buf.length - 1`. **Default:** `0`.
1689 Reads a signed 8-bit integer from `buf` at the specified `offset`.
1694 const buf = Buffer.from([-1, 5]);
1696 console.log(buf.readInt8(0));
1697 // Prints: -1
1698 console.log(buf.readInt8(1));
1700 console.log(buf.readInt8(2));
1705 <!-- YAML
1708 - version: v10.0.0
1709 pr-url: https://github.com/nodejs/node/pull/18395
1710 description: Removed `noAssert` and no implicit coercion of the offset
1712 -->
1715 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
1718 Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
1725 console.log(buf.readInt16BE(0));
1730 <!-- YAML
1733 - version: v10.0.0
1734 pr-url: https://github.com/nodejs/node/pull/18395
1735 description: Removed `noAssert` and no implicit coercion of the offset
1737 -->
1740 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
1743 Reads a signed, little-endian 16-bit integer from `buf` at the specified
1751 console.log(buf.readInt16LE(0));
1753 console.log(buf.readInt16LE(1));
1758 <!-- YAML
1761 - version: v10.0.0
1762 pr-url: https://github.com/nodejs/node/pull/18395
1763 description: Removed `noAssert` and no implicit coercion of the offset
1765 -->
1768 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
1771 Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
1778 console.log(buf.readInt32BE(0));
1783 <!-- YAML
1786 - version: v10.0.0
1787 pr-url: https://github.com/nodejs/node/pull/18395
1788 description: Removed `noAssert` and no implicit coercion of the offset
1790 -->
1793 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
1796 Reads a signed, little-endian 32-bit integer from `buf` at the specified
1804 console.log(buf.readInt32LE(0));
1806 console.log(buf.readInt32LE(1));
1811 <!-- YAML
1814 - version: v10.0.0
1815 pr-url: https://github.com/nodejs/node/pull/18395
1816 description: Removed `noAssert` and no implicit coercion of the offset
1818 -->
1821 satisfy `0 <= offset <= buf.length - byteLength`.
1827 and interprets the result as a big-endian, two's complement signed value
1833 console.log(buf.readIntBE(0, 6).toString(16));
1835 console.log(buf.readIntBE(1, 6).toString(16));
1837 console.log(buf.readIntBE(1, 0).toString(16));
1842 <!-- YAML
1845 - version: v10.0.0
1846 pr-url: https://github.com/nodejs/node/pull/18395
1847 description: Removed `noAssert` and no implicit coercion of the offset
1849 -->
1852 satisfy `0 <= offset <= buf.length - byteLength`.
1858 and interprets the result as a little-endian, two's complement signed value
1864 console.log(buf.readIntLE(0, 6).toString(16));
1865 // Prints: -546f87a9cbee
1869 <!-- YAML
1872 - version: v14.9.0
1873 pr-url: https://github.com/nodejs/node/pull/34729
1875 - version: v10.0.0
1876 pr-url: https://github.com/nodejs/node/pull/18395
1877 description: Removed `noAssert` and no implicit coercion of the offset
1879 -->
1882 satisfy `0 <= offset <= buf.length - 1`. **Default:** `0`.
1885 Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
1890 const buf = Buffer.from([1, -2]);
1892 console.log(buf.readUInt8(0));
1894 console.log(buf.readUInt8(1));
1896 console.log(buf.readUInt8(2));
1901 <!-- YAML
1904 - version: v14.9.0
1905 pr-url: https://github.com/nodejs/node/pull/34729
1907 - version: v10.0.0
1908 pr-url: https://github.com/nodejs/node/pull/18395
1909 description: Removed `noAssert` and no implicit coercion of the offset
1911 -->
1914 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
1917 Reads an unsigned, big-endian 16-bit integer from `buf` at the specified
1925 console.log(buf.readUInt16BE(0).toString(16));
1927 console.log(buf.readUInt16BE(1).toString(16));
1932 <!-- YAML
1935 - version: v14.9.0
1936 pr-url: https://github.com/nodejs/node/pull/34729
1938 - version: v10.0.0
1939 pr-url: https://github.com/nodejs/node/pull/18395
1940 description: Removed `noAssert` and no implicit coercion of the offset
1942 -->
1945 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
1948 Reads an unsigned, little-endian 16-bit integer from `buf` at the specified
1956 console.log(buf.readUInt16LE(0).toString(16));
1958 console.log(buf.readUInt16LE(1).toString(16));
1960 console.log(buf.readUInt16LE(2).toString(16));
1965 <!-- YAML
1968 - version: v14.9.0
1969 pr-url: https://github.com/nodejs/node/pull/34729
1971 - version: v10.0.0
1972 pr-url: https://github.com/nodejs/node/pull/18395
1973 description: Removed `noAssert` and no implicit coercion of the offset
1975 -->
1978 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
1981 Reads an unsigned, big-endian 32-bit integer from `buf` at the specified
1989 console.log(buf.readUInt32BE(0).toString(16));
1994 <!-- YAML
1997 - version: v14.9.0
1998 pr-url: https://github.com/nodejs/node/pull/34729
2000 - version: v10.0.0
2001 pr-url: https://github.com/nodejs/node/pull/18395
2002 description: Removed `noAssert` and no implicit coercion of the offset
2004 -->
2007 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2010 Reads an unsigned, little-endian 32-bit integer from `buf` at the specified
2018 console.log(buf.readUInt32LE(0).toString(16));
2020 console.log(buf.readUInt32LE(1).toString(16));
2025 <!-- YAML
2028 - version: v14.9.0
2029 pr-url: https://github.com/nodejs/node/pull/34729
2031 - version: v10.0.0
2032 pr-url: https://github.com/nodejs/node/pull/18395
2033 description: Removed `noAssert` and no implicit coercion of the offset
2035 -->
2038 satisfy `0 <= offset <= buf.length - byteLength`.
2044 and interprets the result as an unsigned big-endian integer supporting
2052 console.log(buf.readUIntBE(0, 6).toString(16));
2054 console.log(buf.readUIntBE(1, 6).toString(16));
2059 <!-- YAML
2062 - version: v14.9.0
2063 pr-url: https://github.com/nodejs/node/pull/34729
2065 - version: v10.0.0
2066 pr-url: https://github.com/nodejs/node/pull/18395
2067 description: Removed `noAssert` and no implicit coercion of the offset
2069 -->
2072 satisfy `0 <= offset <= buf.length - byteLength`.
2078 and interprets the result as an unsigned, little-endian integer supporting
2086 console.log(buf.readUIntLE(0, 6).toString(16));
2091 <!-- YAML
2093 -->
2124 console.log(buf2.toString('ascii', 0, buf2.length));
2129 console.log(buf2.toString('ascii', 0, buf2.length));
2139 console.log(buf.subarray(-6, -1).toString());
2143 console.log(buf.subarray(-6, -2).toString());
2147 console.log(buf.subarray(-5, -2).toString());
2153 <!-- YAML
2156 - version:
2157 - v7.1.0
2158 - v6.9.2
2159 pr-url: https://github.com/nodejs/node/pull/9341
2161 the 32-bit integer range properly.
2162 - version: v7.0.0
2163 pr-url: https://github.com/nodejs/node/pull/9101
2166 -->
2187 console.log(copiedBuf.toString());
2190 console.log(buf.toString());
2195 <!-- YAML
2197 -->
2201 Interprets `buf` as an array of unsigned 16-bit integers and swaps the
2202 byte order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`][] if [`buf.length`][]
2208 console.log(buf1);
2213 console.log(buf1);
2222 One convenient use of `buf.swap16()` is to perform a fast in-place conversion
2223 between UTF-16 little-endian and UTF-16 big-endian:
2226 const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
2227 buf.swap16(); // Convert to big-endian UTF-16 text.
2231 <!-- YAML
2233 -->
2237 Interprets `buf` as an array of unsigned 32-bit integers and swaps the
2238 byte order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`][] if [`buf.length`][]
2244 console.log(buf1);
2249 console.log(buf1);
2259 <!-- YAML
2261 -->
2265 Interprets `buf` as an array of 64-bit numbers and swaps byte order *in-place*.
2271 console.log(buf1);
2276 console.log(buf1);
2286 <!-- YAML
2288 -->
2302 console.log(json);
2311 console.log(copy);
2316 <!-- YAML
2318 -->
2329 If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
2332 The maximum length of a string instance (in UTF-16 code units) is available
2343 console.log(buf1.toString('utf8'));
2345 console.log(buf1.toString('utf8', 0, 5));
2350 console.log(buf2.toString('hex'));
2352 console.log(buf2.toString('utf8', 0, 3));
2354 console.log(buf2.toString(undefined, 0, 3));
2359 <!-- YAML
2361 -->
2372 console.log(value);
2383 console.log(value);
2395 <!-- YAML
2397 -->
2403 exceed `buf.length - offset`). **Default:** `buf.length - offset`.
2417 console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
2424 console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
2429 <!-- YAML
2431 - v12.0.0
2432 - v10.20.0
2433 -->
2437 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
2440 Writes `value` to `buf` at the specified `offset` as big-endian.
2449 console.log(buf);
2454 <!-- YAML
2456 - v12.0.0
2457 - v10.20.0
2458 -->
2462 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
2465 Writes `value` to `buf` at the specified `offset` as little-endian.
2474 console.log(buf);
2479 <!-- YAML
2481 - v12.0.0
2482 - v10.20.0
2484 - version: v14.10.0
2485 pr-url: https://github.com/nodejs/node/pull/34960
2487 -->
2491 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
2494 Writes `value` to `buf` at the specified `offset` as big-endian.
2503 console.log(buf);
2508 <!-- YAML
2510 - v12.0.0
2511 - v10.20.0
2513 - version: v14.10.0
2514 pr-url: https://github.com/nodejs/node/pull/34960
2516 -->
2520 satisfy: `0 <= offset <= buf.length - 8`. **Default:** `0`.
2523 Writes `value` to `buf` at the specified `offset` as little-endian
2530 console.log(buf);
2537 <!-- YAML
2540 - version: v10.0.0
2541 pr-url: https://github.com/nodejs/node/pull/18395
2542 description: Removed `noAssert` and no implicit coercion of the offset
2544 -->
2548 satisfy `0 <= offset <= buf.length - 8`. **Default:** `0`.
2551 Writes `value` to `buf` at the specified `offset` as big-endian. The `value`
2560 console.log(buf);
2565 <!-- YAML
2568 - version: v10.0.0
2569 pr-url: https://github.com/nodejs/node/pull/18395
2570 description: Removed `noAssert` and no implicit coercion of the offset
2572 -->
2576 satisfy `0 <= offset <= buf.length - 8`. **Default:** `0`.
2579 Writes `value` to `buf` at the specified `offset` as little-endian. The `value`
2588 console.log(buf);
2593 <!-- YAML
2596 - version: v10.0.0
2597 pr-url: https://github.com/nodejs/node/pull/18395
2598 description: Removed `noAssert` and no implicit coercion of the offset
2600 -->
2604 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2607 Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
2615 console.log(buf);
2620 <!-- YAML
2623 - version: v10.0.0
2624 pr-url: https://github.com/nodejs/node/pull/18395
2625 description: Removed `noAssert` and no implicit coercion of the offset
2627 -->
2631 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2634 Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
2642 console.log(buf);
2647 <!-- YAML
2650 - version: v10.0.0
2651 pr-url: https://github.com/nodejs/node/pull/18395
2652 description: Removed `noAssert` and no implicit coercion of the offset
2654 -->
2658 satisfy `0 <= offset <= buf.length - 1`. **Default:** `0`.
2662 signed 8-bit integer. Behavior is undefined when `value` is anything other than
2663 a signed 8-bit integer.
2671 buf.writeInt8(-2, 1);
2673 console.log(buf);
2678 <!-- YAML
2681 - version: v10.0.0
2682 pr-url: https://github.com/nodejs/node/pull/18395
2683 description: Removed `noAssert` and no implicit coercion of the offset
2685 -->
2689 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
2692 Writes `value` to `buf` at the specified `offset` as big-endian. The `value`
2693 must be a valid signed 16-bit integer. Behavior is undefined when `value` is
2694 anything other than a signed 16-bit integer.
2703 console.log(buf);
2708 <!-- YAML
2711 - version: v10.0.0
2712 pr-url: https://github.com/nodejs/node/pull/18395
2713 description: Removed `noAssert` and no implicit coercion of the offset
2715 -->
2719 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
2722 Writes `value` to `buf` at the specified `offset` as little-endian. The `value`
2723 must be a valid signed 16-bit integer. Behavior is undefined when `value` is
2724 anything other than a signed 16-bit integer.
2733 console.log(buf);
2738 <!-- YAML
2741 - version: v10.0.0
2742 pr-url: https://github.com/nodejs/node/pull/18395
2743 description: Removed `noAssert` and no implicit coercion of the offset
2745 -->
2749 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2752 Writes `value` to `buf` at the specified `offset` as big-endian. The `value`
2753 must be a valid signed 32-bit integer. Behavior is undefined when `value` is
2754 anything other than a signed 32-bit integer.
2763 console.log(buf);
2768 <!-- YAML
2771 - version: v10.0.0
2772 pr-url: https://github.com/nodejs/node/pull/18395
2773 description: Removed `noAssert` and no implicit coercion of the offset
2775 -->
2779 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2782 Writes `value` to `buf` at the specified `offset` as little-endian. The `value`
2783 must be a valid signed 32-bit integer. Behavior is undefined when `value` is
2784 anything other than a signed 32-bit integer.
2793 console.log(buf);
2798 <!-- YAML
2801 - version: v10.0.0
2802 pr-url: https://github.com/nodejs/node/pull/18395
2803 description: Removed `noAssert` and no implicit coercion of the offset
2805 -->
2809 satisfy `0 <= offset <= buf.length - byteLength`.
2815 as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when
2823 console.log(buf);
2828 <!-- YAML
2831 - version: v10.0.0
2832 pr-url: https://github.com/nodejs/node/pull/18395
2833 description: Removed `noAssert` and no implicit coercion of the offset
2835 -->
2839 satisfy `0 <= offset <= buf.length - byteLength`.
2845 as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
2853 console.log(buf);
2858 <!-- YAML
2861 - version: v14.9.0
2862 pr-url: https://github.com/nodejs/node/pull/34729
2864 - version: v10.0.0
2865 pr-url: https://github.com/nodejs/node/pull/18395
2866 description: Removed `noAssert` and no implicit coercion of the offset
2868 -->
2872 satisfy `0 <= offset <= buf.length - 1`. **Default:** `0`.
2876 valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
2877 other than an unsigned 8-bit integer.
2889 console.log(buf);
2894 <!-- YAML
2897 - version: v14.9.0
2898 pr-url: https://github.com/nodejs/node/pull/34729
2900 - version: v10.0.0
2901 pr-url: https://github.com/nodejs/node/pull/18395
2902 description: Removed `noAssert` and no implicit coercion of the offset
2904 -->
2908 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
2911 Writes `value` to `buf` at the specified `offset` as big-endian. The `value`
2912 must be a valid unsigned 16-bit integer. Behavior is undefined when `value`
2913 is anything other than an unsigned 16-bit integer.
2923 console.log(buf);
2928 <!-- YAML
2931 - version:
2932 - v14.9.0
2933 - v12.19.0
2934 pr-url: https://github.com/nodejs/node/pull/34729
2936 - version: v10.0.0
2937 pr-url: https://github.com/nodejs/node/pull/18395
2938 description: Removed `noAssert` and no implicit coercion of the offset
2940 -->
2944 satisfy `0 <= offset <= buf.length - 2`. **Default:** `0`.
2947 Writes `value` to `buf` at the specified `offset` as little-endian. The `value`
2948 must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is
2949 anything other than an unsigned 16-bit integer.
2959 console.log(buf);
2964 <!-- YAML
2967 - version: v14.9.0
2968 pr-url: https://github.com/nodejs/node/pull/34729
2970 - version: v10.0.0
2971 pr-url: https://github.com/nodejs/node/pull/18395
2972 description: Removed `noAssert` and no implicit coercion of the offset
2974 -->
2978 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
2981 Writes `value` to `buf` at the specified `offset` as big-endian. The `value`
2982 must be a valid unsigned 32-bit integer. Behavior is undefined when `value`
2983 is anything other than an unsigned 32-bit integer.
2992 console.log(buf);
2997 <!-- YAML
3000 - version: v14.9.0
3001 pr-url: https://github.com/nodejs/node/pull/34729
3003 - version: v10.0.0
3004 pr-url: https://github.com/nodejs/node/pull/18395
3005 description: Removed `noAssert` and no implicit coercion of the offset
3007 -->
3011 satisfy `0 <= offset <= buf.length - 4`. **Default:** `0`.
3014 Writes `value` to `buf` at the specified `offset` as little-endian. The `value`
3015 must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is
3016 anything other than an unsigned 32-bit integer.
3025 console.log(buf);
3030 <!-- YAML
3033 - version: v14.9.0
3034 pr-url: https://github.com/nodejs/node/pull/34729
3036 - version: v10.0.0
3037 pr-url: https://github.com/nodejs/node/pull/18395
3038 description: Removed `noAssert` and no implicit coercion of the offset
3040 -->
3044 satisfy `0 <= offset <= buf.length - byteLength`.
3050 as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
3060 console.log(buf);
3065 <!-- YAML
3068 - version: v14.9.0
3069 pr-url: https://github.com/nodejs/node/pull/34729
3071 - version: v10.0.0
3072 pr-url: https://github.com/nodejs/node/pull/18395
3073 description: Removed `noAssert` and no implicit coercion of the offset
3075 -->
3079 satisfy `0 <= offset <= buf.length - byteLength`.
3085 as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
3095 console.log(buf);
3100 <!-- YAML
3103 - version: v10.0.0
3104 pr-url: https://github.com/nodejs/node/pull/19524
3107 - version: v7.2.1
3108 pr-url: https://github.com/nodejs/node/pull/9529
3109 description: Calling this constructor no longer emits a deprecation warning.
3110 - version: v7.0.0
3111 pr-url: https://github.com/nodejs/node/pull/8169
3113 -->
3115 > Stability: 0 - Deprecated: Use [`Buffer.from(array)`][] instead.
3122 <!-- YAML
3126 - version: v10.0.0
3127 pr-url: https://github.com/nodejs/node/pull/19524
3130 - version: v7.2.1
3131 pr-url: https://github.com/nodejs/node/pull/9529
3132 description: Calling this constructor no longer emits a deprecation warning.
3133 - version: v7.0.0
3134 pr-url: https://github.com/nodejs/node/pull/8169
3136 - version: v6.0.0
3137 pr-url: https://github.com/nodejs/node/pull/4682
3139 -->
3141 > Stability: 0 - Deprecated: Use
3149 **Default:** `arrayBuffer.byteLength - byteOffset`.
3155 <!-- YAML
3158 - version: v10.0.0
3159 pr-url: https://github.com/nodejs/node/pull/19524
3162 - version: v7.2.1
3163 pr-url: https://github.com/nodejs/node/pull/9529
3164 description: Calling this constructor no longer emits a deprecation warning.
3165 - version: v7.0.0
3166 pr-url: https://github.com/nodejs/node/pull/8169
3168 -->
3170 > Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`][] instead.
3178 <!-- YAML
3181 - version: v10.0.0
3182 pr-url: https://github.com/nodejs/node/pull/19524
3185 - version: v8.0.0
3186 pr-url: https://github.com/nodejs/node/pull/12141
3187 description: The `new Buffer(size)` will return zero-filled memory by
3189 - version: v7.2.1
3190 pr-url: https://github.com/nodejs/node/pull/9529
3191 description: Calling this constructor no longer emits a deprecation warning.
3192 - version: v7.0.0
3193 pr-url: https://github.com/nodejs/node/pull/8169
3195 -->
3197 > Stability: 0 - Deprecated: Use [`Buffer.alloc()`][] instead (also see
3206 <!-- YAML
3209 - version: v10.0.0
3210 pr-url: https://github.com/nodejs/node/pull/19524
3213 - version: v7.2.1
3214 pr-url: https://github.com/nodejs/node/pull/9529
3215 description: Calling this constructor no longer emits a deprecation warning.
3216 - version: v7.0.0
3217 pr-url: https://github.com/nodejs/node/pull/8169
3219 -->
3221 > Stability: 0 - Deprecated:
3232 `Buffer`-related APIs that are available only via the `buffer` module
3236 <!-- YAML
3238 -->
3240 * `data` {any} The Base64-encoded input string.
3242 Decodes a string of Base64-encoded data into bytes, and encodes those bytes
3243 into a string using Latin-1 (ISO-8859-1).
3245 The `data` may be any JavaScript-value that can be coerced into a string.
3250 For code running using Node.js APIs, converting between base64-encoded strings
3255 <!-- YAML
3257 -->
3261 Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
3264 The `data` may be any JavaScript-value that can be coerced into a string.
3269 For code running using Node.js APIs, converting between base64-encoded strings
3274 <!-- YAML
3276 -->
3285 <!-- YAML
3287 -->
3294 <!-- YAML
3296 -->
3303 <!-- YAML
3306 - version: v8.0.0
3307 pr-url: https://github.com/nodejs/node/pull/10236
3309 -->
3316 Re-encodes the given `Buffer` or `Uint8Array` instance from one character
3332 console.log(newBuf.toString('ascii'));
3336 Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
3340 <!-- YAML
3342 -->
3344 > Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.
3351 <!-- YAML
3353 -->
3355 > Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.
3362 <!-- YAML
3364 -->
3367 <!-- YAML
3370 - version: v14.0.0
3371 pr-url: https://github.com/nodejs/node/pull/32116
3372 description: Value is changed from 2<sup>31</sup> - 1 to
3373 2<sup>32</sup> - 1 on 64-bit architectures.
3374 -->
3378 On 32-bit architectures, this value currently is 2<sup>30</sup> - 1 (~1GB).
3380 On 64-bit architectures, this value currently is 2<sup>32</sup> - 1 (~4GB).
3387 <!-- YAML
3389 -->
3394 in UTF-16 code units.
3412 required between creating a fast-but-uninitialized `Buffer` versus creating a
3413 slower-but-safer `Buffer`. Since Node.js 8.0.0, `Buffer(num)` and `new
3433 arbitrary pre-existing in-memory data, so may be used to expose in-memory
3435 occur because the data is zero-filled. However, other attacks are still
3439 To make the creation of `Buffer` instances more reliable and less error-prone,
3473 ### The `--zero-fill-buffers` command-line option
3474 <!-- YAML
3476 -->
3478 Node.js can be started using the `--zero-fill-buffers` command-line option to
3479 cause all newly-allocated `Buffer` instances to be zero-filled upon creation by
3481 [`Buffer.allocUnsafeSlow()`][], and `new SlowBuffer(size)` are not zero-filled.
3483 `--zero-fill-buffers` option only when necessary to enforce that newly allocated
3486 ```console
3487 $ node --zero-fill-buffers
3495 segment of allocated memory is *uninitialized* (it is not zeroed-out). While
3507 [ISO-8859-1]: https://en.wikipedia.org/wiki/ISO-8859-1
3508 [RFC 4648, Section 5]: https://tools.ietf.org/html/rfc4648#section-5
3509 [UTF-16]: https://en.wikipedia.org/wiki/UTF-16
3510 [UTF-8]: https://en.wikipedia.org/wiki/UTF-8
3512 [`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/A…
3513 [`Blob`]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
3523 [`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Data…
3527 [`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obje…
3528 [`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj…
3529 [`String.prototype.indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
3530 [`String.prototype.lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
3531 [`String.prototype.length`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob…
3532 [`TypedArray.from()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj…
3533 [`TypedArray.prototype.set()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G…
3534 [`TypedArray.prototype.slice()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
3535 [`TypedArray.prototype.subarray()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere…
3536 [`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ty…
3537 [`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ui…
3553 [base64url]: https://tools.ietf.org/html/rfc4648#section-5
3554 [binary strings]: https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary
3556 [iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols