Fixes to image serialization

This commit is contained in:
Don Jayamanne 2021-09-16 15:59:41 -07:00
parent 6dff4e5fde
commit 1eb4ff560b

View file

@ -276,11 +276,7 @@ function convertOutputMimeToJupyterOutput(mime: string, value: Uint8Array) {
if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {
return Buffer.from(value).toString('base64');
} else {
// https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_1_%E2%80%93_escaping_the_string_before_encoding_it
const stringValue = textDecoder.decode(value);
return btoa(encodeURIComponent(stringValue).replace(/%([0-9A-F]{2})/g, function (_match, p1) {
return String.fromCharCode(Number.parseInt('0x' + p1));
}));
return btoa(value.reduce((s: string, b: number) => s + String.fromCharCode(b), ''));
}
} else if (mime.toLowerCase().includes('json')) {
const stringValue = textDecoder.decode(value);