diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-09-11 02:13:01 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-09-25 19:20:53 +0300 |
commit | 772a5e06581e9715aebb0facf3c79b6436650212 (patch) | |
tree | aa27598c007a6442e407a7a232402cd92b524b37 /doc/api | |
parent | dd5d944005166fbbfd4b72b9779f398598b3481d (diff) |
util: add encodeInto to TextEncoder
Add function encodeInto to TextEncoder, and add MessageChannel
to the encodeInto.any.js test.
Fixes: https://github.com/nodejs/node/issues/28851
Fixes: https://github.com/nodejs/node/issues/26904
Refs: https://github.com/nodejs/node/pull/28862
Co-authored-by: AtticusYang <yyongtai@163.com>
PR-URL: https://github.com/nodejs/node/pull/29524
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api')
-rw-r--r-- | doc/api/util.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/util.md b/doc/api/util.md index 135ecc12bff..e2ff7b974e2 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -1057,6 +1057,24 @@ The `TextEncoder` class is also available on the global object. UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes. +### textEncoder.encodeInto(src, dest) + +* `src` {string} The text to encode. +* `dest` {Uint8Array} The array to hold the encode result. +* Returns: {Object} + * `read` {number} The read Unicode code units of src. + * `written` {number} The written UTF-8 bytes of dest. + +UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object +containing the read Unicode code units and written UTF-8 bytes. + +```js +const encoder = new TextEncoder(); +const src = 'this is some data'; +const dest = new Uint8Array(10); +const { read, written } = encoder.encodeInto(src, dest); +``` + ### textEncoder.encoding * {string} |