nika-begiashvili / libarchivejs

Archive library for browsers
MIT License
288 stars 35 forks source link

About file compressing feature. #74

Closed xbridges closed 2 months ago

xbridges commented 2 months ago

Thanks published this great library. I tried compress feature on browser. Below is

  1. A file select by browser.
  2. test 1.jpg compress and download success, but invalid size and invalid zip file.

log in browser develop tool compress_test

zip binary data binary

tried source code.

import { Archive, ArchiveCompression, ArchiveFormat } from "./dist/libarchive.js";

document.getElementById("file").addEventListener("change", async (e) => {
  try {
    Archive.init({
        workerUrl: "./dist/worker-bundle.js",
    });
    window.Archive = Archive;

    const file = e.currentTarget.files[0];
    const imageFiles = [{ file }];

    console.log(imageFiles);

    const archivedFile = await Archive.write({
            files: imageFiles,
            outputFileName: "test.zip",
            compression: ArchiveCompression.GZIP,
            format: ArchiveFormat.ZIP,
          });
    console.log(archivedFile);

    // download file
    const a = document.createElement('a');
    a.href = URL.createObjectURL(archivedFile);
    a.download = `test.zip`;
    a.click();

  } catch (err) {
    console.error(err);
  }
});

I'd like you to point out the bad points please.

xbridges commented 2 months ago

Sorry. I will close this issue. I solved it myself. My preparing process was incorrect.