Skip to content

Commit

Permalink
Reverting handling of blob imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NickGeek committed Jul 20, 2019
1 parent 511b2fd commit efebe6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upad-parse",
"version": "6.2.3",
"version": "6.2.4",
"description": "This is a parser for the NPX file format that µPad uses",
"main": "dist/index.js",
"scripts": {
Expand Down
18 changes: 17 additions & 1 deletion src/Translators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,23 @@ export namespace Translators {
export type MarkdownImport = { title: string, content: string };
}

// Thanks to http://stackoverflow.com/a/12300351/998467
async function dataURItoBlob(dataURI: string) {
return fetch(dataURI).then(res => res.blob());
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
let byteString = atob(dataURI.split(',')[1]);

// separate out the mime component
let mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

// write the bytes of the string to an ArrayBuffer
let ab = new ArrayBuffer(byteString.length);
let ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}

// write the ArrayBuffer to a blob, and you're done
return new Blob([ia], { type: mimeString });
}
}

0 comments on commit efebe6a

Please sign in to comment.