Skip to content

Commit

Permalink
#3914 Add support for opening structures in CDX format embedded into …
Browse files Browse the repository at this point in the history
…MS PowerPoint fix decoding for large arrays
  • Loading branch information
captain2b committed Jan 26, 2024
1 parent 316c720 commit a11b6e0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/ketcher-react/src/script/ui/utils/fileOpener.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export function fileOpener(server) {
});
}

function arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}

function throughFileReader(file) {
const CDX = 'cdx';
const PPTX = 'pptx';
Expand Down Expand Up @@ -67,9 +77,7 @@ function throughFileReader(file) {
if (path.endsWith('.bin')) {
const ole = CFB.find(cfb, path);
const sdf = CFB.find(CFB.parse(ole.content), 'CONTENTS');
const base64String = btoa(
String.fromCharCode(...new Uint8Array(sdf.content)),
);
const base64String = arrayBufferToBase64(sdf.content);
structures.push(base64String);
}
});
Expand Down

0 comments on commit a11b6e0

Please sign in to comment.