2
2
3
3
Stability: 2 - Stable
4
4
5
- Pure JavaScript is Unicode friendly but not nice to binary data. When
5
+ Pure JavaScript is Unicode- friendly but not nice to binary data. When
6
6
dealing with TCP streams or the file system, it's necessary to handle octet
7
7
streams. Node.js has several strategies for manipulating, creating, and
8
8
consuming octet streams.
@@ -15,23 +15,23 @@ The `Buffer` class is a global, making it very rare that one would need
15
15
to ever ` require('buffer') ` .
16
16
17
17
Converting between Buffers and JavaScript string objects requires an explicit
18
- encoding method. Here are the different string encodings.
18
+ encoding method. The different string encodings are:
19
19
20
- * ` 'ascii' ` - for 7 bit ASCII data only. This encoding method is very fast, and
20
+ * ` 'ascii' ` - for 7- bit ASCII data only. This encoding method is very fast and
21
21
will strip the high bit if set.
22
22
23
23
* ` 'utf8' ` - Multibyte encoded Unicode characters. Many web pages and other
24
24
document formats use UTF-8.
25
25
26
- * ` 'utf16le' ` - 2 or 4 bytes, little endian encoded Unicode characters.
26
+ * ` 'utf16le' ` - 2 or 4 bytes, little- endian encoded Unicode characters.
27
27
Surrogate pairs (U+10000 to U+10FFFF) are supported.
28
28
29
29
* ` 'ucs2' ` - Alias of ` 'utf16le' ` .
30
30
31
31
* ` 'base64' ` - Base64 string encoding.
32
32
33
- * ` 'binary' ` - A way of encoding the buffer into a one-byte (i.e. ` latin-1 ` )
34
- encoded string. The string ` 'latin-1' ` is not supported. Instead simply pass
33
+ * ` 'binary' ` - A way of encoding the buffer into a one-byte (` latin-1 ` )
34
+ encoded string. The string ` 'latin-1' ` is not supported. Instead, pass
35
35
` 'binary' ` to use ` 'latin-1' ` encoding.
36
36
37
37
* ` 'hex' ` - Encode each byte as two hexadecimal characters.
@@ -45,8 +45,8 @@ Creating a typed array from a `Buffer` works with the following caveats:
45
45
with elements ` [1,2,3,4] ` , not a ` Uint32Array ` with a single element
46
46
` [0x1020304] ` or ` [0x4030201] ` .
47
47
48
- NOTE: Node.js v0.8 simply retained a reference to the buffer in ` array.buffer `
49
- instead of cloning it.
48
+ NOTE: Node.js v0.8 retained a reference to the buffer in ` array.buffer ` instead
49
+ of cloning it.
50
50
51
51
While more efficient, it introduces subtle incompatibilities with the typed
52
52
arrays specification. ` ArrayBuffer#slice() ` makes a copy of the slice while
@@ -74,9 +74,9 @@ Copies the passed `buffer` data onto a new `Buffer` instance.
74
74
* ` size ` Number
75
75
76
76
Allocates a new buffer of ` size ` bytes. ` size ` must be less than
77
- 1,073,741,824 bytes (1 GB) on 32 bits architectures or
78
- 2,147,483,648 bytes (2 GB) on 64 bits architectures,
79
- otherwise a [ ` RangeError ` ] [ ] is thrown.
77
+ 1,073,741,824 bytes (1 GB) on 32-bit architectures or
78
+ 2,147,483,648 bytes (2 GB) on 64-bit architectures.
79
+ Otherwise, a [ ` RangeError ` ] [ ] is thrown.
80
80
81
81
Unlike ` ArrayBuffers ` , the underlying memory for buffers is not initialized. So
82
82
the contents of a newly created ` Buffer ` are unknown and could contain
@@ -208,14 +208,14 @@ Example: copy an ASCII string into a buffer, one byte at a time:
208
208
209
209
// Node.js
210
210
211
- Returns a boolean of whether ` this ` and ` otherBuffer ` have the same
211
+ Returns a boolean indicating whether ` this ` and ` otherBuffer ` have the same
212
212
bytes.
213
213
214
214
### buf.compare(otherBuffer)
215
215
216
216
* ` otherBuffer ` {Buffer}
217
217
218
- Returns a number indicating whether ` this ` comes before or after or is
218
+ Returns a number indicating whether ` this ` comes before, after, or is
219
219
the same as the ` otherBuffer ` in sort order.
220
220
221
221
@@ -227,7 +227,7 @@ the same as the `otherBuffer` in sort order.
227
227
* ` sourceEnd ` Number, Optional, Default: ` buffer.length `
228
228
229
229
Copies data from a region of this buffer to a region in the target buffer even
230
- if the target memory region overlaps with the source. If ` undefined ` the
230
+ if the target memory region overlaps with the source. If ` undefined ` , the
231
231
` targetStart ` and ` sourceStart ` parameters default to ` 0 ` while ` sourceEnd `
232
232
defaults to ` buffer.length ` .
233
233
@@ -326,7 +326,7 @@ use [`buf.slice`][] to create a new buffer.
326
326
* ` noAssert ` Boolean, Optional, Default: false
327
327
* Return: Number
328
328
329
- Reads a 64 bit double from the buffer at the specified offset with specified
329
+ Reads a 64- bit double from the buffer at the specified offset with specified
330
330
endian format.
331
331
332
332
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -356,7 +356,7 @@ Example:
356
356
* ` noAssert ` Boolean, Optional, Default: false
357
357
* Return: Number
358
358
359
- Reads a 32 bit float from the buffer at the specified offset with specified
359
+ Reads a 32- bit float from the buffer at the specified offset with specified
360
360
endian format.
361
361
362
362
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -381,7 +381,7 @@ Example:
381
381
* ` noAssert ` Boolean, Optional, Default: false
382
382
* Return: Number
383
383
384
- Reads a signed 8 bit integer from the buffer at the specified offset.
384
+ Reads a signed 8- bit integer from the buffer at the specified offset.
385
385
386
386
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
387
387
may be beyond the end of the buffer. Defaults to ` false ` .
@@ -396,7 +396,7 @@ complement signed values.
396
396
* ` noAssert ` Boolean, Optional, Default: false
397
397
* Return: Number
398
398
399
- Reads a signed 16 bit integer from the buffer at the specified offset with
399
+ Reads a signed 16- bit integer from the buffer at the specified offset with
400
400
specified endian format.
401
401
402
402
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -412,7 +412,7 @@ complement signed values.
412
412
* ` noAssert ` Boolean, Optional, Default: false
413
413
* Return: Number
414
414
415
- Reads a signed 32 bit integer from the buffer at the specified offset with
415
+ Reads a signed 32- bit integer from the buffer at the specified offset with
416
416
specified endian format.
417
417
418
418
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -447,7 +447,7 @@ may be beyond the end of the buffer. Defaults to `false`.
447
447
* ` noAssert ` Boolean, Optional, Default: false
448
448
* Return: Number
449
449
450
- Reads an unsigned 8 bit integer from the buffer at the specified offset.
450
+ Reads an unsigned 8- bit integer from the buffer at the specified offset.
451
451
452
452
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
453
453
may be beyond the end of the buffer. Defaults to ` false ` .
@@ -477,7 +477,7 @@ Example:
477
477
* ` noAssert ` Boolean, Optional, Default: false
478
478
* Return: Number
479
479
480
- Reads an unsigned 16 bit integer from the buffer at the specified offset with
480
+ Reads an unsigned 16- bit integer from the buffer at the specified offset with
481
481
specified endian format.
482
482
483
483
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -513,7 +513,7 @@ Example:
513
513
* ` noAssert ` Boolean, Optional, Default: false
514
514
* Return: Number
515
515
516
- Reads an unsigned 32 bit integer from the buffer at the specified offset with
516
+ Reads an unsigned 32- bit integer from the buffer at the specified offset with
517
517
specified endian format.
518
518
519
519
Set ` noAssert ` to true to skip validation of ` offset ` . This means that ` offset `
@@ -604,7 +604,7 @@ See `buffer.write()` example, above.
604
604
605
605
### buf.toJSON()
606
606
607
- Returns a JSON- representation of the Buffer instance. ` JSON.stringify `
607
+ Returns a JSON representation of the Buffer instance. ` JSON.stringify `
608
608
implicitly calls this function when stringifying a Buffer instance.
609
609
610
610
Example:
@@ -650,7 +650,7 @@ The method will not write partial characters.
650
650
* ` noAssert ` Boolean, Optional, Default: false
651
651
652
652
Writes ` value ` to the buffer at the specified offset with specified endian
653
- format. Note, ` value ` must be a valid 64 bit double.
653
+ format. ` value ` must be a valid 64- bit double.
654
654
655
655
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
656
656
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -679,7 +679,7 @@ Example:
679
679
* ` noAssert ` Boolean, Optional, Default: false
680
680
681
681
Writes ` value ` to the buffer at the specified offset with specified endian
682
- format. Note, behavior is unspecified if ` value ` is not a 32 bit float.
682
+ format. Behavior is unspecified if ` value ` is not a 32- bit float.
683
683
684
684
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
685
685
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -706,8 +706,8 @@ Example:
706
706
* ` offset ` Number
707
707
* ` noAssert ` Boolean, Optional, Default: false
708
708
709
- Writes ` value ` to the buffer at the specified offset. Note, ` value ` must be a
710
- valid signed 8 bit integer.
709
+ Writes ` value ` to the buffer at the specified offset. ` value ` must be a
710
+ valid signed 8- bit integer.
711
711
712
712
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
713
713
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -725,7 +725,7 @@ signed integer into `buffer`.
725
725
* ` noAssert ` Boolean, Optional, Default: false
726
726
727
727
Writes ` value ` to the buffer at the specified offset with specified endian
728
- format. Note, ` value ` must be a valid signed 16 bit integer.
728
+ format. ` value ` must be a valid signed 16- bit integer.
729
729
730
730
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
731
731
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -743,7 +743,7 @@ complement signed integer into `buffer`.
743
743
* ` noAssert ` Boolean, Optional, Default: false
744
744
745
745
Writes ` value ` to the buffer at the specified offset with specified endian
746
- format. Note, ` value ` must be a valid signed 32 bit integer.
746
+ format. ` value ` must be a valid signed 32- bit integer.
747
747
748
748
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
749
749
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -778,8 +778,8 @@ to `false`.
778
778
* ` offset ` Number
779
779
* ` noAssert ` Boolean, Optional, Default: false
780
780
781
- Writes ` value ` to the buffer at the specified offset. Note, ` value ` must be a
782
- valid unsigned 8 bit integer.
781
+ Writes ` value ` to the buffer at the specified offset. ` value ` must be a
782
+ valid unsigned 8- bit integer.
783
783
784
784
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
785
785
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -806,7 +806,7 @@ Example:
806
806
* ` noAssert ` Boolean, Optional, Default: false
807
807
808
808
Writes ` value ` to the buffer at the specified offset with specified endian
809
- format. Note, ` value ` must be a valid unsigned 16 bit integer.
809
+ format. ` value ` must be a valid unsigned 16- bit integer.
810
810
811
811
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
812
812
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -837,7 +837,7 @@ Example:
837
837
* ` noAssert ` Boolean, Optional, Default: false
838
838
839
839
Writes ` value ` to the buffer at the specified offset with specified endian
840
- format. Note, ` value ` must be a valid unsigned 32 bit integer.
840
+ format. ` value ` must be a valid unsigned 32- bit integer.
841
841
842
842
Set ` noAssert ` to true to skip validation of ` value ` and ` offset ` . This means
843
843
that ` value ` may be too large for the specific function and ` offset ` may be
@@ -886,7 +886,7 @@ be overridden by user modules. See [`util.inspect()`][] for more details on
886
886
` buffer.inspect() ` behavior.
887
887
888
888
Note that this is a property on the buffer module returned by
889
- ` require('buffer') ` , not on the Buffer global, or a buffer instance.
889
+ ` require('buffer') ` , not on the Buffer global or a buffer instance.
890
890
891
891
## ES6 iteration
892
892
@@ -901,7 +901,7 @@ Buffers can be iterated over using `for..of` syntax:
901
901
// 2
902
902
// 3
903
903
904
- Additionally, ` buffer.values() ` , ` buffer.keys() ` and ` buffer.entries() `
904
+ Additionally, the ` buffer.values() ` , ` buffer.keys() ` , and ` buffer.entries() `
905
905
methods can be used to create iterators.
906
906
907
907
## Class: SlowBuffer
@@ -914,7 +914,7 @@ larger allocated object. This approach improves both performance and memory
914
914
usage since v8 does not need to track and cleanup as many ` Persistent ` objects.
915
915
916
916
In the case where a developer may need to retain a small chunk of memory from a
917
- pool for an indeterminate amount of time it may be appropriate to create an
917
+ pool for an indeterminate amount of time, it may be appropriate to create an
918
918
un-pooled Buffer instance using SlowBuffer and copy out the relevant bits.
919
919
920
920
// need to keep around a few small chunks of memory
@@ -929,8 +929,8 @@ un-pooled Buffer instance using SlowBuffer and copy out the relevant bits.
929
929
store.push(sb);
930
930
});
931
931
932
- Though this should be used sparingly and only be a last resort * after* a developer
933
- has actively observed undue memory retention in their applications.
932
+ This should be used only as a last resort * after* a developer has observed
933
+ undue memory retention in their applications.
934
934
935
935
[ `Array#indexOf()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
936
936
[ `buf.fill(0)` ] : #buffer_buf_fill_value_offset_end
0 commit comments