Skip to content

Instantly share code, notes, and snippets.

@jessecogollo
Created October 23, 2017 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessecogollo/ce0e90e1fad85fecbd43d17340b4ca3b to your computer and use it in GitHub Desktop.
Save jessecogollo/ce0e90e1fad85fecbd43d17340b4ca3b to your computer and use it in GitHub Desktop.
TextEncoder and TextDecoder
'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