Skip to content

add() for ZipSync #131

Closed
Closed

Description

@AlttiRi

JSZip has a short and clear example.

I think it would convenient if this lib supports this approach from the box:

const zip = new fflate.ZipSync();
zip.add({
    filename: "image.png",
    data: imgData, // `ArrayBuffer`/`TypedArray`
});

zip.add({
    filename: "docs/text.txt",
    data: "The example text" // `String`, just use `new TextEncoder().encode(data)` in this case
    mtime: new Date("2022-12-22 12:15:00")
});

/** @type {Uint8Array} */
const zipBytes = zip.end();

Optionally, the same approach for async version:

const zip = new fflate.Zip();
await zip.add({
    filename: "image.png",
    data: imgBlob, // additionally `Blob`/`File` support?
});

const resp = await fetch("https://example.com");
void zip.add({
    filename: "sites/example.com.html",
    data: resp.body // `ReadableStream`
});

const zipBytes = await zip.end();

Activity

  1. 101arrowz commented on May 21, 2022

    @101arrowz
    Owner

    fflate's philosophy is to avoid validating or checking input and to not allow shorthands except where it yields no impact on bundle size, so this is not going to be implemented.

    However, I am currently working on ezzip, an fflate wrapper with convenience features like these and modern APIs. I will take this feature request into consideration there and update here once it's published.

  2. AlttiRi commented on Jun 13, 2022

    @AlttiRi
    Author

    Also a wrapper for zipping a directory with a few lines of codes would be useful for Node.js.

    Something like this:

    const zip = new fflate.ZipSync();
    zip.add({path: "./dir"});
    zip.write("./result.zip");
  3. Repository owner locked and limited conversation to collaborators on Sep 30, 2022
  4. converted this issue into a discussion #146 on Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions