@@ -230,9 +230,9 @@ const arr = new Uint16Array(2);
230230arr[0 ] = 5000 ;
231231arr[1 ] = 4000 ;
232232
233- // Copies the contents of `arr`
233+ // Copies the contents of `arr`.
234234const buf1 = Buffer .from (arr);
235- // Shares memory with `arr`
235+ // Shares memory with `arr`.
236236const buf2 = Buffer .from (arr .buffer );
237237
238238console .log (buf1);
@@ -322,7 +322,7 @@ changes:
322322Allocates a new ` Buffer ` using an ` array ` of octets.
323323
324324``` js
325- // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'
325+ // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
326326const buf = new Buffer ([0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 ]);
327327```
328328
@@ -370,13 +370,13 @@ const arr = new Uint16Array(2);
370370arr[0 ] = 5000 ;
371371arr[1 ] = 4000 ;
372372
373- // Shares memory with `arr`
373+ // Shares memory with `arr`.
374374const buf = new Buffer (arr .buffer );
375375
376376console .log (buf);
377377// Prints: <Buffer 88 13 a0 0f>
378378
379- // Changing the original Uint16Array changes the Buffer also
379+ // Changing the original Uint16Array changes the Buffer also.
380380arr[1 ] = 6000 ;
381381
382382console .log (buf);
@@ -585,7 +585,7 @@ initialized*. The contents of the newly created `Buffer` are unknown and
585585const buf = Buffer .allocUnsafe (10 );
586586
587587console .log (buf);
588- // Prints: (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
588+ // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
589589
590590buf .fill (0 );
591591
@@ -638,16 +638,16 @@ to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
638638then copying out the relevant bits.
639639
640640``` js
641- // Need to keep around a few small chunks of memory
641+ // Need to keep around a few small chunks of memory.
642642const store = [];
643643
644644socket .on (' readable' , () => {
645645 let data;
646646 while (null !== (data = readable .read ())) {
647- // Allocate for retained data
647+ // Allocate for retained data.
648648 const sb = Buffer .allocUnsafeSlow (10 );
649649
650- // Copy the data into the new allocation
650+ // Copy the data into the new allocation.
651651 data .copy (sb, 0 , 0 , 10 );
652652
653653 store .push (sb);
@@ -722,7 +722,7 @@ const arr = [buf1, buf2];
722722
723723console .log (arr .sort (Buffer .compare ));
724724// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
725- // (This result is equal to: [buf2, buf1])
725+ // (This result is equal to: [buf2, buf1]. )
726726```
727727
728728### Class Method: Buffer.concat(list[ , totalLength] )
@@ -784,7 +784,7 @@ added: v5.10.0
784784Allocates a new ` Buffer ` using an ` array ` of octets.
785785
786786``` js
787- // Creates a new Buffer containing UTF-8 bytes of the string 'buffer'
787+ // Creates a new Buffer containing UTF-8 bytes of the string 'buffer'.
788788const buf = Buffer .from ([0x62 , 0x75 , 0x66 , 0x66 , 0x65 , 0x72 ]);
789789```
790790
@@ -813,13 +813,13 @@ const arr = new Uint16Array(2);
813813arr[0 ] = 5000 ;
814814arr[1 ] = 4000 ;
815815
816- // Shares memory with `arr`
816+ // Shares memory with `arr`.
817817const buf = Buffer .from (arr .buffer );
818818
819819console .log (buf);
820820// Prints: <Buffer 88 13 a0 0f>
821821
822- // Changing the original Uint16Array changes the Buffer also
822+ // Changing the original Uint16Array changes the Buffer also.
823823arr[1 ] = 6000 ;
824824
825825console .log (buf);
@@ -1076,7 +1076,7 @@ console.log(buf2.compare(buf3));
10761076// Prints: 1
10771077console .log ([buf1, buf2, buf3].sort (Buffer .compare ));
10781078// Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
1079- // (This result is equal to: [buf1, buf3, buf2])
1079+ // (This result is equal to: [buf1, buf3, buf2]. )
10801080```
10811081
10821082The optional ` targetStart ` , ` targetEnd ` , ` sourceStart ` , and ` sourceEnd `
@@ -1121,11 +1121,11 @@ const buf1 = Buffer.allocUnsafe(26);
11211121const buf2 = Buffer .allocUnsafe (26 ).fill (' !' );
11221122
11231123for (let i = 0 ; i < 26 ; i++ ) {
1124- // 97 is the decimal ASCII value for 'a'
1124+ // 97 is the decimal ASCII value for 'a'.
11251125 buf1[i] = i + 97 ;
11261126}
11271127
1128- // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`
1128+ // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
11291129buf1 .copy (buf2, 8 , 16 , 20 );
11301130
11311131console .log (buf2 .toString (' ascii' , 0 , 25 ));
@@ -1139,7 +1139,7 @@ console.log(buf2.toString('ascii', 0, 25));
11391139const buf = Buffer .allocUnsafe (26 );
11401140
11411141for (let i = 0 ; i < 26 ; i++ ) {
1142- // 97 is the decimal ASCII value for 'a'
1142+ // 97 is the decimal ASCII value for 'a'.
11431143 buf[i] = i + 97 ;
11441144}
11451145
@@ -1374,13 +1374,13 @@ behavior matches [`String#indexOf()`].
13741374``` js
13751375const b = Buffer .from (' abcdef' );
13761376
1377- // Passing a value that's a number, but not a valid byte
1378- // Prints: 2, equivalent to searching for 99 or 'c'
1377+ // Passing a value that's a number, but not a valid byte.
1378+ // Prints: 2, equivalent to searching for 99 or 'c'.
13791379console .log (b .indexOf (99.9 ));
13801380console .log (b .indexOf (256 + 99 ));
13811381
1382- // Passing a byteOffset that coerces to NaN or 0
1383- // Prints: 1, searching the whole buffer
1382+ // Passing a byteOffset that coerces to NaN or 0.
1383+ // Prints: 1, searching the whole buffer.
13841384console .log (b .indexOf (' b' , undefined ));
13851385console .log (b .indexOf (' b' , {}));
13861386console .log (b .indexOf (' b' , null ));
@@ -1474,18 +1474,18 @@ This behavior matches [`String#lastIndexOf()`].
14741474``` js
14751475const b = Buffer .from (' abcdef' );
14761476
1477- // Passing a value that's a number, but not a valid byte
1478- // Prints: 2, equivalent to searching for 99 or 'c'
1477+ // Passing a value that's a number, but not a valid byte.
1478+ // Prints: 2, equivalent to searching for 99 or 'c'.
14791479console .log (b .lastIndexOf (99.9 ));
14801480console .log (b .lastIndexOf (256 + 99 ));
14811481
1482- // Passing a byteOffset that coerces to NaN
1483- // Prints: 1, searching the whole buffer
1482+ // Passing a byteOffset that coerces to NaN.
1483+ // Prints: 1, searching the whole buffer.
14841484console .log (b .lastIndexOf (' b' , undefined ));
14851485console .log (b .lastIndexOf (' b' , {}));
14861486
1487- // Passing a byteOffset that coerces to 0
1488- // Prints: -1, equivalent to passing 0
1487+ // Passing a byteOffset that coerces to 0.
1488+ // Prints: -1, equivalent to passing 0.
14891489console .log (b .lastIndexOf (' b' , null ));
14901490console .log (b .lastIndexOf (' b' , []));
14911491```
@@ -1571,7 +1571,7 @@ console.log(buf.readDoubleBE(0));
15711571console .log (buf .readDoubleLE (0 ));
15721572// Prints: 5.447603722011605e-270
15731573console .log (buf .readDoubleLE (1 ));
1574- // Throws ERR_OUT_OF_RANGE
1574+ // Throws ERR_OUT_OF_RANGE.
15751575```
15761576
15771577### buf.readFloatBE([ offset] )
@@ -1601,7 +1601,7 @@ console.log(buf.readFloatBE(0));
16011601console .log (buf .readFloatLE (0 ));
16021602// Prints: 1.539989614439558e-36
16031603console .log (buf .readFloatLE (1 ));
1604- // Throws ERR_OUT_OF_RANGE
1604+ // Throws ERR_OUT_OF_RANGE.
16051605```
16061606
16071607### buf.readInt8([ offset] )
@@ -1630,7 +1630,7 @@ console.log(buf.readInt8(0));
16301630console .log (buf .readInt8 (1 ));
16311631// Prints: 5
16321632console .log (buf .readInt8 (2 ));
1633- // Throws ERR_OUT_OF_RANGE
1633+ // Throws ERR_OUT_OF_RANGE.
16341634```
16351635
16361636### buf.readInt16BE([ offset] )
@@ -1662,7 +1662,7 @@ console.log(buf.readInt16BE(0));
16621662console .log (buf .readInt16LE (0 ));
16631663// Prints: 1280
16641664console .log (buf .readInt16LE (1 ));
1665- // Throws ERR_OUT_OF_RANGE
1665+ // Throws ERR_OUT_OF_RANGE.
16661666```
16671667
16681668### buf.readInt32BE([ offset] )
@@ -1694,7 +1694,7 @@ console.log(buf.readInt32BE(0));
16941694console .log (buf .readInt32LE (0 ));
16951695// Prints: 83886080
16961696console .log (buf .readInt32LE (1 ));
1697- // Throws ERR_OUT_OF_RANGE
1697+ // Throws ERR_OUT_OF_RANGE.
16981698```
16991699
17001700### buf.readIntBE(offset, byteLength)
@@ -1726,9 +1726,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
17261726console .log (buf .readIntBE (0 , 6 ).toString (16 ));
17271727// Prints: 1234567890ab
17281728console .log (buf .readIntBE (1 , 6 ).toString (16 ));
1729- // Throws ERR_OUT_OF_RANGE
1729+ // Throws ERR_OUT_OF_RANGE.
17301730console .log (buf .readIntBE (1 , 0 ).toString (16 ));
1731- // Throws ERR_OUT_OF_RANGE
1731+ // Throws ERR_OUT_OF_RANGE.
17321732```
17331733
17341734### buf.readUInt8([ offset] )
@@ -1755,7 +1755,7 @@ console.log(buf.readUInt8(0));
17551755console .log (buf .readUInt8 (1 ));
17561756// Prints: 254
17571757console .log (buf .readUInt8 (2 ));
1758- // Throws ERR_OUT_OF_RANGE
1758+ // Throws ERR_OUT_OF_RANGE.
17591759```
17601760
17611761### buf.readUInt16BE([ offset] )
@@ -1789,7 +1789,7 @@ console.log(buf.readUInt16BE(1).toString(16));
17891789console .log (buf .readUInt16LE (1 ).toString (16 ));
17901790// Prints: 5634
17911791console .log (buf .readUInt16LE (2 ).toString (16 ));
1792- // Throws ERR_OUT_OF_RANGE
1792+ // Throws ERR_OUT_OF_RANGE.
17931793```
17941794
17951795### buf.readUInt32BE([ offset] )
@@ -1819,7 +1819,7 @@ console.log(buf.readUInt32BE(0).toString(16));
18191819console .log (buf .readUInt32LE (0 ).toString (16 ));
18201820// Prints: 78563412
18211821console .log (buf .readUInt32LE (1 ).toString (16 ));
1822- // Throws ERR_OUT_OF_RANGE
1822+ // Throws ERR_OUT_OF_RANGE.
18231823```
18241824
18251825### buf.readUIntBE(offset, byteLength)
@@ -1851,7 +1851,7 @@ console.log(buf.readUIntBE(0, 6).toString(16));
18511851console .log (buf .readUIntLE (0 , 6 ).toString (16 ));
18521852// Prints: ab9078563412
18531853console .log (buf .readUIntBE (1 , 6 ).toString (16 ));
1854- // Throws ERR_OUT_OF_RANGE
1854+ // Throws ERR_OUT_OF_RANGE.
18551855```
18561856
18571857### buf.slice([ start[ , end]] )
@@ -1889,7 +1889,7 @@ because the allocated memory of the two objects overlap.
18891889const buf1 = Buffer .allocUnsafe (26 );
18901890
18911891for (let i = 0 ; i < 26 ; i++ ) {
1892- // 97 is the decimal ASCII value for 'a'
1892+ // 97 is the decimal ASCII value for 'a'.
18931893 buf1[i] = i + 97 ;
18941894}
18951895
@@ -1912,15 +1912,15 @@ const buf = Buffer.from('buffer');
19121912
19131913console .log (buf .slice (- 6 , - 1 ).toString ());
19141914// Prints: buffe
1915- // (Equivalent to buf.slice(0, 5))
1915+ // (Equivalent to buf.slice(0, 5). )
19161916
19171917console .log (buf .slice (- 6 , - 2 ).toString ());
19181918// Prints: buff
1919- // (Equivalent to buf.slice(0, 4))
1919+ // (Equivalent to buf.slice(0, 4). )
19201920
19211921console .log (buf .slice (- 5 , - 2 ).toString ());
19221922// Prints: uff
1923- // (Equivalent to buf.slice(1, 4))
1923+ // (Equivalent to buf.slice(1, 4). )
19241924```
19251925
19261926### buf.swap16()
@@ -1948,7 +1948,7 @@ console.log(buf1);
19481948const buf2 = Buffer .from ([0x1 , 0x2 , 0x3 ]);
19491949
19501950buf2 .swap16 ();
1951- // Throws ERR_INVALID_BUFFER_SIZE
1951+ // Throws ERR_INVALID_BUFFER_SIZE.
19521952```
19531953
19541954One convenient use of ` buf.swap16() ` is to perform a fast in-place conversion
@@ -1984,7 +1984,7 @@ console.log(buf1);
19841984const buf2 = Buffer .from ([0x1 , 0x2 , 0x3 ]);
19851985
19861986buf2 .swap32 ();
1987- // Throws ERR_INVALID_BUFFER_SIZE
1987+ // Throws ERR_INVALID_BUFFER_SIZE.
19881988```
19891989
19901990### buf.swap64()
@@ -2011,7 +2011,7 @@ console.log(buf1);
20112011const buf2 = Buffer .from ([0x1 , 0x2 , 0x3 ]);
20122012
20132013buf2 .swap64 ();
2014- // Throws ERR_INVALID_BUFFER_SIZE
2014+ // Throws ERR_INVALID_BUFFER_SIZE.
20152015```
20162016
20172017Note that JavaScript cannot encode 64-bit integers. This method is intended
@@ -2065,7 +2065,7 @@ as [`buffer.constants.MAX_STRING_LENGTH`][].
20652065const buf1 = Buffer .allocUnsafe (26 );
20662066
20672067for (let i = 0 ; i < 26 ; i++ ) {
2068- // 97 is the decimal ASCII value for 'a'
2068+ // 97 is the decimal ASCII value for 'a'.
20692069 buf1[i] = i + 97 ;
20702070}
20712071
@@ -2573,16 +2573,16 @@ pool for an indeterminate amount of time, it may be appropriate to create an
25732573un-pooled ` Buffer ` instance using ` SlowBuffer ` then copy out the relevant bits.
25742574
25752575``` js
2576- // Need to keep around a few small chunks of memory
2576+ // Need to keep around a few small chunks of memory.
25772577const store = [];
25782578
25792579socket .on (' readable' , () => {
25802580 let data;
25812581 while (null !== (data = readable .read ())) {
2582- // Allocate for retained data
2582+ // Allocate for retained data.
25832583 const sb = SlowBuffer (10 );
25842584
2585- // Copy the data into the new allocation
2585+ // Copy the data into the new allocation.
25862586 data .copy (sb, 0 , 0 , 10 );
25872587
25882588 store .push (sb);
0 commit comments