Skip to content
Discussion options

You must be logged in to vote

Check out demo site: https://101arrowz.github.io/fflate/

You cannot add File object directly, you have to read files first. This is example with Promise, so you can easily use it with async/await:

function readFile(file: File) {
  return new Promise<Uint8Array>((resolve, reject) => {
    const reader = new FileReader();

    reader.onloadend = () => {
      resolve(new Uint8Array(reader.result as ArrayBuffer));
    };
    reader.onerror = reject;
    reader.readAsArrayBuffer(file);
  });
}

Then you have to create archive structure, for example:

const archiveStruct: AsyncZippable = {}
for (const file of files) {
    const fileBuffer = await readFile(file);
    archiveStruct[file.name] = fi…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@101arrowz
Comment options

Answer selected by 101arrowz
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@realrecordzLab
Comment options

@101arrowz
Comment options

Comment options

You must be logged in to vote
2 replies
@101arrowz
Comment options

@realrecordzLab
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #20 on December 29, 2020 19:36.