Skip to content

Improve zip documentation #185

Answered by 101arrowz
HarelM asked this question in Q&A
Oct 8, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

To zip a file (like in your first link):

const result = fflate.zipSync({ 'log.txt': fflate.strToU8('some text') });

// convert to a blob if you need
const resultBlob = new Blob([result]);

To unzip (like in your other link):

const zipData = new Uint8Array(await yourBlob.arrayBuffer());
const files = fflate.unzipSync(zipData, {
  filter: file => file.name.startsWith("styles/") && file.name.endsWith(".json")
});

for (const fileName in files) {
  const styleText = fflate.strFromU8(files[fileName]);
  // do whatever you want here
}

If you care about not blocking the main thread, you can replace the zipSync or unzipSync calls with zip or unzip, e.g.

// first example
const result = await new P…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by 101arrowz
Comment options

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

@101arrowz
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
2 participants
Converted from issue

This discussion was converted from issue #184 on October 08, 2023 20:20.