diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-09-11 01:13:01 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-09-13 20:27:18 +0200 |
commit | 7c9ee6dd88cc2908a3db70eba9c15eddd1112c50 (patch) | |
tree | b1f35efd2e6de2b41a962088d12e26eb8bf6121e /doc | |
parent | 3675f402ab1114675c5be7950d38b7e168ba5771 (diff) | |
download | android-node-v8-7c9ee6dd88cc2908a3db70eba9c15eddd1112c50.tar.gz android-node-v8-7c9ee6dd88cc2908a3db70eba9c15eddd1112c50.tar.bz2 android-node-v8-7c9ee6dd88cc2908a3db70eba9c15eddd1112c50.zip |
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')
-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 8fab6baaaf..46637941df 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -1076,6 +1076,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} |