|
4 | 4 |
|
5 | 5 | > Stability: 2 - Stable
|
6 | 6 |
|
7 |
| -Prior to the introduction of [`TypedArray`] in [`ECMAScript 2015`] (ES6), the |
8 |
| -JavaScript language had no mechanism for reading or manipulating streams |
9 |
| -of binary data. The `Buffer` class was introduced as part of the Node.js |
10 |
| -API to make it possible to interact with octet streams in the context of things |
11 |
| -like TCP streams and file system operations. |
| 7 | +Prior to the introduction of [`TypedArray`], the JavaScript language had no |
| 8 | +mechanism for reading or manipulating streams of binary data. The `Buffer` class |
| 9 | +was introduced as part of the Node.js API to make it possible to interact with |
| 10 | +octet streams in the context of things like TCP streams and file system |
| 11 | +operations. |
12 | 12 |
|
13 |
| -Now that [`TypedArray`] has been added in ES6, the `Buffer` class implements the |
14 |
| -[`Uint8Array`] API in a manner that is more optimized and suitable for Node.js' |
15 |
| -use cases. |
| 13 | +With [`TypedArray`] now available, the `Buffer` class implements the |
| 14 | +[`Uint8Array`] API in a manner that is more optimized and suitable for Node.js. |
16 | 15 |
|
17 | 16 | Instances of the `Buffer` class are similar to arrays of integers but
|
18 | 17 | correspond to fixed-sized, raw memory allocations outside the V8 heap.
|
@@ -211,11 +210,10 @@ changes:
|
211 | 210 | -->
|
212 | 211 |
|
213 | 212 | `Buffer` instances are also [`Uint8Array`] instances. However, there are subtle
|
214 |
| -incompatibilities with the TypedArray specification in [`ECMAScript 2015`]. |
215 |
| -For example, while [`ArrayBuffer#slice()`] creates a copy of the slice, the |
216 |
| -implementation of [`Buffer#slice()`][`buf.slice()`] creates a view over the |
217 |
| -existing `Buffer` without copying, making [`Buffer#slice()`][`buf.slice()`] far |
218 |
| -more efficient. |
| 213 | +incompatibilities with [`TypedArray`]. For example, while |
| 214 | +[`ArrayBuffer#slice()`] creates a copy of the slice, the implementation of |
| 215 | +[`Buffer#slice()`][`buf.slice()`] creates a view over the existing `Buffer` |
| 216 | +without copying, making [`Buffer#slice()`][`buf.slice()`] far more efficient. |
219 | 217 |
|
220 | 218 | It is also possible to create new [`TypedArray`] instances from a `Buffer` with
|
221 | 219 | the following caveats:
|
@@ -289,10 +287,9 @@ function:
|
289 | 287 | * [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`]
|
290 | 288 | * [`Buffer.from(string[, encoding])`][`Buffer.from(string)`]
|
291 | 289 |
|
292 |
| -## Buffers and ES6 iteration |
| 290 | +## Buffers and iteration |
293 | 291 |
|
294 |
| -`Buffer` instances can be iterated over using the [`ECMAScript 2015`] (ES6) `for..of` |
295 |
| -syntax. |
| 292 | +`Buffer` instances can be iterated over using `for..of` syntax: |
296 | 293 |
|
297 | 294 | Example:
|
298 | 295 |
|
@@ -2757,5 +2754,4 @@ This value may depend on the JS engine that is being used.
|
2757 | 2754 | [RFC1345]: https://tools.ietf.org/html/rfc1345
|
2758 | 2755 | [RFC4648, Section 5]: https://tools.ietf.org/html/rfc4648#section-5
|
2759 | 2756 | [WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/
|
2760 |
| -[`ECMAScript 2015`]: https://www.ecma-international.org/ecma-262/6.0/index.html |
2761 | 2757 | [iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
0 commit comments