Skip to content

Commit 1b4083e

Browse files
authored
Correctly save content even if format is base64 (#45)
* Correctly save content even if format is base64 * Fix lint error
1 parent cd55d9d commit 1b4083e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/drive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function arrayBufferToBase64(buffer: ArrayBuffer): string {
1818
return window.btoa(binary);
1919
}
2020

21+
function base64DecodeAsBlob(text: string, type = 'text/plain;charset=UTF-8') {
22+
return fetch(`data:${type};base64,` + text).then(response => response.blob());
23+
}
24+
2125
async function toArray<T>(
2226
asyncIterator: AsyncIterableIterator<T>
2327
): Promise<T[]> {
@@ -255,6 +259,9 @@ export class FileSystemDrive implements Contents.IDrive {
255259
if (format === 'json') {
256260
const data = JSON.stringify(content, null, 2);
257261
await writable.write(data);
262+
} else if (format === 'base64') {
263+
const contentBlob = await base64DecodeAsBlob(content);
264+
await writable.write(contentBlob);
258265
} else {
259266
await writable.write(content);
260267
}

0 commit comments

Comments
 (0)