diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:01:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:19:39 +0000 |
commit | 56eec1de7018759c0ec251dba4455c18f73c3bbd (patch) | |
tree | 3aeb2d10356530bc2cc3f24e74f41048a13885b4 /src/text.js | |
parent | Initial commit. (diff) | |
download | zmodemjs-upstream/0.1.10+dfsg.tar.xz zmodemjs-upstream/0.1.10+dfsg.zip |
Adding upstream version 0.1.10+dfsg.upstream/0.1.10+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/text.js')
-rw-r--r-- | src/text.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/text.js b/src/text.js new file mode 100644 index 0000000..d267817 --- /dev/null +++ b/src/text.js @@ -0,0 +1,33 @@ +class _my_TextEncoder { + encode(text) { + text = unescape(encodeURIComponent(text)); + + var bytes = new Array( text.length ); + + for (var b = 0; b < text.length; b++) { + bytes[b] = text.charCodeAt(b); + } + + return new Uint8Array(bytes); + } +} + +class _my_TextDecoder { + decode(bytes) { + return decodeURIComponent( escape( String.fromCharCode.apply(String, bytes) ) ); + } +} + +var Zmodem = module.exports; + +/** + * A limited-use compatibility shim for TextEncoder and TextDecoder. + * Useful because both Edge and node.js still lack support for these + * as of October 2017. + * + * @exports Text + */ +Zmodem.Text = { + Encoder: (typeof TextEncoder !== "undefined") ? TextEncoder : _my_TextEncoder, + Decoder: (typeof TextDecoder !== "undefined") ? TextDecoder : _my_TextDecoder, +}; |