diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 093be3f09e9232..bda9e3a4f91a24 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -282,7 +282,7 @@ const buf = Buffer.from([1, 2, 3]); // 1 // 2 // 3 -for (var b of buf) { +for (const b of buf) { console.log(b); } ``` @@ -404,14 +404,14 @@ to initialize a `Buffer` to zeroes. Example: ```js -const buf = new Buffer(5); +const buf = new Buffer(10); -// Prints: (contents may vary): +// Prints: (contents may vary): console.log(buf); buf.fill(0); -// Prints: +// Prints: console.log(buf); ``` @@ -523,14 +523,14 @@ initialized*. The contents of the newly created `Buffer` are unknown and Example: ```js -const buf = Buffer.allocUnsafe(5); +const buf = Buffer.allocUnsafe(10); -// Prints: (contents may vary): +// Prints: (contents may vary): console.log(buf); buf.fill(0); -// Prints: +// Prints: console.log(buf); ``` @@ -995,7 +995,7 @@ overlapping region within the same `Buffer` ```js const buf = Buffer.allocUnsafe(26); -for (var i = 0 ; i < 26 ; i++) { +for (let i = 0 ; i < 26 ; i++) { // 97 is the decimal ASCII value for 'a' buf[i] = i + 97; } @@ -1028,7 +1028,7 @@ const buf = Buffer.from('buffer'); // [3, 102] // [4, 101] // [5, 114] -for (var pair of buf.entries()) { +for (const pair of buf.entries()) { console.log(pair); } ``` @@ -1122,7 +1122,7 @@ Examples: const buf = Buffer.from('this is a buffer'); // Prints: 0 -console.log(buf.indexOf('this'))); +console.log(buf.indexOf('this')); // Prints: 2 console.log(buf.indexOf('is')); @@ -1212,7 +1212,7 @@ const buf = Buffer.from('buffer'); // 3 // 4 // 5 -for (var key of buf.keys()) { +for (const key of buf.keys()) { console.log(key); } ``` @@ -1223,8 +1223,8 @@ added: v6.0.0 --> * `value` {String | Buffer | Integer} What to search for -* `byteOffset` {Integer} Where to begin searching in `buf` (not inclusive). - **Default:** [`buf.length`] +* `byteOffset` {Integer} Where to begin searching in `buf`. + **Default:** [`buf.length`]` - 1` * `encoding` {String} If `value` is a string, this is its encoding. **Default:** `'utf8'` * Returns: {Integer} The index of the last occurrence of `value` in `buf` or `-1` @@ -1264,7 +1264,7 @@ console.log(buf.lastIndexOf('buffer', 4)); const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); // Prints: 6 -console.log(utf16Buffer.lastIndexOf('\u03a3', null, 'ucs2')); +console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'ucs2')); // Prints: 4 console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'ucs2')); @@ -1302,7 +1302,7 @@ use [`buf.slice()`] to create a new `Buffer`. Examples: ```js -var buf = Buffer.allocUnsafe(10); +let buf = Buffer.allocUnsafe(10); buf.write('abcdefghj', 0, 'ascii'); @@ -1446,7 +1446,7 @@ const buf = Buffer.from([0, 5]); console.log(buf.readInt16BE()); // Prints: 1280 -console.log(buf.readInt16LE(1)); +console.log(buf.readInt16LE()); // Throws an exception: RangeError: Index out of range console.log(buf.readInt16LE(1)); @@ -1509,10 +1509,10 @@ Examples: ```js const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); -// Prints: 1234567890ab +// Prints: -546f87a9cbee console.log(buf.readIntLE(0, 6).toString(16)); -// Prints: -546f87a9cbee +// Prints: 1234567890ab console.log(buf.readIntBE(0, 6).toString(16)); // Throws an exception: RangeError: Index out of range @@ -1673,7 +1673,7 @@ one byte from the original `Buffer` ```js const buf1 = Buffer.allocUnsafe(26); -for (var i = 0 ; i < 26 ; i++) { +for (let i = 0 ; i < 26 ; i++) { // 97 is the decimal ASCII value for 'a' buf1[i] = i + 97; } @@ -1737,7 +1737,7 @@ console.log(buf1); const buf2 = Buffer.from([0x1, 0x2, 0x3]); // Throws an exception: RangeError: Buffer size must be a multiple of 16-bits -buf2.swap32(); +buf2.swap16(); ``` ### buf.swap32() @@ -1822,7 +1822,7 @@ Examples: ```js const buf1 = Buffer.allocUnsafe(26); -for (var i = 0 ; i < 26 ; i++) { +for (let i = 0 ; i < 26 ; i++) { // 97 is the decimal ASCII value for 'a' buf1[i] = i + 97; } @@ -1897,7 +1897,7 @@ const buf = Buffer.from('buffer'); // 102 // 101 // 114 -for (var value of buf.values()) { +for (const value of buf.values()) { console.log(value); } @@ -1908,7 +1908,7 @@ for (var value of buf.values()) { // 102 // 101 // 114 -for (var value of buf) { +for (const value of buf) { console.log(value); } ``` @@ -2293,7 +2293,7 @@ Returns the maximum number of bytes that will be returned when `buf.inspect()` is called. This can be overridden by user modules. See [`util.inspect()`] for more details on `buf.inspect()` behavior. -Note that this is a property on the `buffer` module as returned by +Note that this is a property on the `buffer` module returned by `require('buffer')`, not on the `Buffer` global or a `Buffer` instance. ## buffer.kMaxLength @@ -2306,6 +2306,9 @@ added: v3.0.0 On 32-bit architectures, this value is `(2^30)-1` (~1GB). On 64-bit architectures, this value is `(2^31)-1` (~2GB). +Note that this is a property on the `buffer` module returned by +`require('buffer')`, not on the `Buffer` global or a `Buffer` instance. + ## buffer.transcode(source, fromEnc, toEnc)