@@ -447,8 +447,8 @@ changes:
447
447
* ` size ` {integer} The desired length of the new ` Buffer `
448
448
449
449
Allocates a new ` Buffer ` of ` size ` bytes. If the ` size ` is larger than
450
- [ ` buffer.kMaxLength ` ] or smaller than 0, a [ ` RangeError ` ] will be thrown.
451
- A zero-length ` Buffer ` will be created if ` size ` is 0.
450
+ [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, a [ ` RangeError ` ] will be
451
+ thrown. A zero-length ` Buffer ` will be created if ` size ` is 0.
452
452
453
453
Prior to Node.js 8.0.0, the underlying memory for ` Buffer ` instances
454
454
created in this way is * not initialized* . The contents of a newly created
@@ -528,8 +528,8 @@ console.log(buf);
528
528
```
529
529
530
530
Allocates a new ` Buffer ` of ` size ` bytes. If the ` size ` is larger than
531
- [ ` buffer.kMaxLength ` ] or smaller than 0, a [ ` RangeError ` ] will be thrown.
532
- A zero-length ` Buffer ` will be created if ` size ` is 0.
531
+ [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, a [ ` RangeError ` ] will be
532
+ thrown. A zero-length ` Buffer ` will be created if ` size ` is 0.
533
533
534
534
If ` fill ` is specified, the allocated ` Buffer ` will be initialized by calling
535
535
[ ` buf.fill(fill) ` ] [ `buf.fill()` ] .
@@ -573,8 +573,8 @@ changes:
573
573
* ` size ` {integer} The desired length of the new ` Buffer `
574
574
575
575
Allocates a new ` Buffer ` of ` size ` bytes. If the ` size ` is larger than
576
- [ ` buffer.kMaxLength ` ] or smaller than 0, a [ ` RangeError ` ] will be thrown.
577
- A zero-length ` Buffer ` will be created if ` size ` is 0.
576
+ [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, a [ ` RangeError ` ] will be
577
+ thrown. A zero-length ` Buffer ` will be created if ` size ` is 0.
578
578
579
579
The underlying memory for ` Buffer ` instances created in this way is * not
580
580
initialized* . The contents of the newly created ` Buffer ` are unknown and
@@ -619,8 +619,8 @@ added: v5.10.0
619
619
* ` size ` {integer} The desired length of the new ` Buffer `
620
620
621
621
Allocates a new ` Buffer ` of ` size ` bytes. If the ` size ` is larger than
622
- [ ` buffer.kMaxLength ` ] or smaller than 0, a [ ` RangeError ` ] will be thrown.
623
- A zero-length ` Buffer ` will be created if ` size ` is 0.
622
+ [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, a [ ` RangeError ` ] will be
623
+ thrown. A zero-length ` Buffer ` will be created if ` size ` is 0.
624
624
625
625
The underlying memory for ` Buffer ` instances created in this way is * not
626
626
initialized* . The contents of the newly created ` Buffer ` are unknown and
@@ -2050,6 +2050,9 @@ added: v0.1.90
2050
2050
Decodes ` buf ` to a string according to the specified character encoding in
2051
2051
` encoding ` . ` start ` and ` end ` may be passed to decode only a subset of ` buf ` .
2052
2052
2053
+ The maximum length of a string instance (in UTF-16 code units) is available
2054
+ as [ ` buffer.constants.MAX_STRING_LENGTH ` ] [ ] .
2055
+
2053
2056
Examples:
2054
2057
2055
2058
``` js
@@ -2507,8 +2510,7 @@ added: v3.0.0
2507
2510
2508
2511
* {integer} The largest size allowed for a single ` Buffer ` instance
2509
2512
2510
- On 32-bit architectures, this value is ` (2^30)-1 ` (~ 1GB).
2511
- On 64-bit architectures, this value is ` (2^31)-1 ` (~ 2GB).
2513
+ An alias for [ ` buffer.constants.MAX_LENGTH ` ] [ ]
2512
2514
2513
2515
Note that this is a property on the ` buffer ` module returned by
2514
2516
` require('buffer') ` , not on the ` Buffer ` global or a ` Buffer ` instance.
@@ -2599,8 +2601,8 @@ deprecated: v6.0.0
2599
2601
* ` size ` {integer} The desired length of the new ` SlowBuffer `
2600
2602
2601
2603
Allocates a new ` Buffer ` of ` size ` bytes. If the ` size ` is larger than
2602
- [ ` buffer.kMaxLength ` ] or smaller than 0, a [ ` RangeError ` ] will be thrown.
2603
- A zero-length ` Buffer ` will be created if ` size ` is 0.
2604
+ [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, a [ ` RangeError ` ] will be
2605
+ thrown. A zero-length ` Buffer ` will be created if ` size ` is 0.
2604
2606
2605
2607
The underlying memory for ` SlowBuffer ` instances is * not initialized* . The
2606
2608
contents of a newly created ` SlowBuffer ` are unknown and may contain
@@ -2622,6 +2624,39 @@ buf.fill(0);
2622
2624
console .log (buf);
2623
2625
```
2624
2626
2627
+
2628
+ ## Buffer Constants
2629
+ <!-- YAML
2630
+ added: REPLACEME
2631
+ -->
2632
+
2633
+ Note that ` buffer.constants ` is a property on the ` buffer ` module returned by
2634
+ ` require('buffer') ` , not on the ` Buffer ` global or a ` Buffer ` instance.
2635
+
2636
+ ### buffer.constants.MAX_LENGTH
2637
+ <!-- YAML
2638
+ added: REPLACEME
2639
+ -->
2640
+
2641
+ * {integer} The largest size allowed for a single ` Buffer ` instance
2642
+
2643
+ On 32-bit architectures, this value is ` (2^30)-1 ` (~ 1GB).
2644
+ On 64-bit architectures, this value is ` (2^31)-1 ` (~ 2GB).
2645
+
2646
+ This value is also available as [ ` buffer.kMaxLength ` ] [ ] .
2647
+
2648
+ ### buffer.constants.MAX_STRING_LENGTH
2649
+ <!-- YAML
2650
+ added: REPLACEME
2651
+ -->
2652
+
2653
+ * {integer} The largest length allowed for a single ` string ` instance
2654
+
2655
+ Represents the largest ` length ` that a ` string ` primitive can have, counted
2656
+ in UTF-16 code units.
2657
+
2658
+ This value may depend on the JS engine that is being used.
2659
+
2625
2660
[ `ArrayBuffer#slice()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice
2626
2661
[ `ArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
2627
2662
[ `Buffer.alloc()` ] : #buffer_class_method_buffer_alloc_size_fill_encoding
@@ -2652,6 +2687,8 @@ console.log(buf);
2652
2687
[ `buf.slice()` ] : #buffer_buf_slice_start_end
2653
2688
[ `buf.values()` ] : #buffer_buf_values
2654
2689
[ `buffer.kMaxLength` ] : #buffer_buffer_kmaxlength
2690
+ [ `buffer.constants.MAX_LENGTH` ] : #buffer_buffer_constants_max_length
2691
+ [ `buffer.constants.MAX_STRING_LENGTH` ] : #buffer_buffer_constants_max_string_length
2655
2692
[ `util.inspect()` ] : util.html#util_util_inspect_object_options
2656
2693
[ RFC1345 ] : https://tools.ietf.org/html/rfc1345
2657
2694
[ RFC4648, Section 5 ] : https://tools.ietf.org/html/rfc4648#section-5
0 commit comments