Created
October 23, 2017 06:47
-
-
Save jessecogollo/ce0e90e1fad85fecbd43d17340b4ca3b to your computer and use it in GitHub Desktop.
TextEncoder and TextDecoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { | |
TextEncoder, | |
TextDecoder | |
} = require('util'); | |
let original = 'this is some data'; | |
const encoder = new TextEncoder(); | |
const uint8array = encoder.encode(original); | |
console.log('uint8array', uint8array); | |
const decoder = new TextDecoder('utf-8'); | |
let string = ''; | |
string += decoder.decode(uint8array, {stream: true}); | |
string += decoder.decode(); | |
console.log('string', string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment