Skip to content

Commit

Permalink
feat(endo): Add zip
Browse files Browse the repository at this point in the history
Our current archive format of choice is Zip.  Our current implementation of choice is stuk/jszip.  Endo's functions that interact with archives assume an Archive interface with read, write, data, and a from-data constructor.  To decouple Endo's internals from the specifics of JSZip, this thin adapter presents the JSZip API as this Archive interface.
  • Loading branch information
kriskowal committed Jun 24, 2020
1 parent f1670c4 commit f32e1ea
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/endo/src/zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Decouples Endo's usage from JSZip's particular presentation.

import JSZip from "jszip";

export const readZip = async data => {
const zip = new JSZip();
await zip.loadAsync(data);
const read = async path => zip.file(path).async("uint8array");
return { read };
};

export const writeZip = () => {
const zip = new JSZip();
const write = async (path, data) => zip.file(path, data);
const data = async () => zip.generateAsync({ type: "uint8array" });
return { write, data };
};

0 comments on commit f32e1ea

Please sign in to comment.