| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 75d23ab commit c8fa8f1
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,15 +5,14 @@ | |||
| 5 | 5 | ||
| 6 | 6 | > Stability: 2 - Stable | |
| 7 | 7 | ||
| 8 | - Prior to the introduction of [`TypedArray`] in [`ECMAScript 2015`] (ES6), the | ||
| 9 | - JavaScript language had no mechanism for reading or manipulating streams | ||
| 10 | - of binary data. The `Buffer` class was introduced as part of the Node.js | ||
| 11 | - API to make it possible to interact with octet streams in the context of things | ||
| 12 | - like TCP streams and file system operations. | ||
| 8 | + Prior to the introduction of [`TypedArray`], the JavaScript language had no | ||
| 9 | + mechanism for reading or manipulating streams of binary data. The `Buffer` class | ||
| 10 | + was introduced as part of the Node.js API to make it possible to interact with | ||
| 11 | + octet streams in the context of things like TCP streams and file system | ||
| 12 | + operations. | ||
| 13 | 13 | ||
| 14 | - Now that [`TypedArray`] has been added in ES6, the `Buffer` class implements the | ||
| 15 | - [`Uint8Array`] API in a manner that is more optimized and suitable for Node.js' | ||
| 16 | - use cases. | ||
| 14 | + With [`TypedArray`] now available, the `Buffer` class implements the | ||
| 15 | + [`Uint8Array`] API in a manner that is more optimized and suitable for Node.js. | ||
| 17 | 16 | ||
| 18 | 17 | Instances of the `Buffer` class are similar to arrays of integers but | |
| 19 | 18 | correspond to fixed-sized, raw memory allocations outside the V8 heap. | |
@@ -207,11 +206,10 @@ changes: | |||
| 207 | 206 | --> | |
| 208 | 207 | ||
| 209 | 208 | `Buffer` instances are also [`Uint8Array`] instances. However, there are subtle | |
| 210 | - incompatibilities with the TypedArray specification in [`ECMAScript 2015`]. | ||
| 211 | - For example, while [`ArrayBuffer#slice()`] creates a copy of the slice, the | ||
| 212 | - implementation of [`Buffer#slice()`][`buf.slice()`] creates a view over the | ||
| 213 | - existing `Buffer` without copying, making [`Buffer#slice()`][`buf.slice()`] far | ||
| 214 | - more efficient. | ||
| 209 | + incompatibilities with [`TypedArray`]. For example, while | ||
| 210 | + [`ArrayBuffer#slice()`] creates a copy of the slice, the implementation of | ||
| 211 | + [`Buffer#slice()`][`buf.slice()`] creates a view over the existing `Buffer` | ||
| 212 | + without copying, making [`Buffer#slice()`][`buf.slice()`] far more efficient. | ||
| 215 | 213 | ||
| 216 | 214 | It is also possible to create new [`TypedArray`] instances from a `Buffer` with | |
| 217 | 215 | the following caveats: | |
@@ -278,10 +276,9 @@ function: | |||
| 278 | 276 | * [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] | |
| 279 | 277 | * [`Buffer.from(string[, encoding])`][`Buffer.from(string)`] | |
| 280 | 278 | ||
| 281 | - ## Buffers and ES6 iteration | ||
| 279 | + ## Buffers and iteration | ||
| 282 | 280 | ||
| 283 | - `Buffer` instances can be iterated over using the [`ECMAScript 2015`] (ES6) `for..of` | ||
| 284 | - syntax. | ||
| 281 | + `Buffer` instances can be iterated over using `for..of` syntax: | ||
| 285 | 282 | ||
| 286 | 283 | ```js | |
| 287 | 284 | const buf = Buffer.from([1, 2, 3]); | |
@@ -2552,5 +2549,4 @@ This value may depend on the JS engine that is being used. | |||
| 2552 | 2549 | [RFC1345]: https://tools.ietf.org/html/rfc1345 | |
| 2553 | 2550 | [RFC4648, Section 5]: https://tools.ietf.org/html/rfc4648#section-5 | |
| 2554 | 2551 | [WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/ | |
| 2555 | - [`ECMAScript 2015`]: https://www.ecma-international.org/ecma-262/6.0/index.html | ||
| 2556 | 2552 | [iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | |
| Back | FazBrowse Home | New Git URL |
0 commit comments