Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created February 16, 2021 17:58
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 mattdesl/3e9877f959e4c1b54d33b089138c70c4 to your computer and use it in GitHub Desktop.
Save mattdesl/3e9877f959e4c1b54d33b089138c70c4 to your computer and use it in GitHub Desktop.
// setup a new encoder with a write callback
const enc = Module.create_encoder(writeEncodedData);
// do some encoding
// ...
// dispose encoder
Module.free_encoder(enc);
// The write callback
function writeEncodedData (pointer, size) {
// Get the encoded data array
const data = Module.HEAPU8.slice(pointer, pointer + size);
// And write it to a stream
myStream.write(data);
return 0; // Write status code 0 = success
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment