Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun support #480

Closed
ghoullier opened this issue Jan 26, 2024 · 4 comments
Closed

Bun support #480

ghoullier opened this issue Jan 26, 2024 · 4 comments

Comments

@ghoullier
Copy link

Purpose

The example below does not works with bun.

import { BlobWriter, TextReader, ZipWriter } from "@zip.js/zip.js";

const zipFileWriter = new BlobWriter();
const helloWorldReader = new TextReader("Hello world!");

const zipWriter = new ZipWriter(zipFileWriter);
await zipWriter.add("hello.txt", helloWorldReader);
await zipWriter.close();

It raises the following exception:

227 |   if (classicWorkersSupported) {
228 |     try {
229 |       worker = new Worker(scriptUrl);
230 |     } catch (_error) {
231 |       classicWorkersSupported = false;
232 |       worker = new Worker(scriptUrl, workerOptions);
                        ^
TypeError: BuildMessage: ModuleNotFound resolving "/Users/gregory.houllier/Playground/play-bun/node_modules/@zip.js/zip.js/lib/undefined" (entry point)
      at getWebWorker (~/play-bun/node_modules/@zip.js/zip.js/lib/core/codec-worker.js:232:16)
      at createWebWorkerInterface (~/play-bun/node_modules/@zip.js/zip.js/lib/core/codec-worker.js:124:15)
      at new CodecWorker (~/play-bun/node_modules/@zip.js/zip.js/lib/core/codec-worker.js:74:6)
      at ~/play-bun/node_modules/@zip.js/zip.js/lib/core/codec-pool.js:75:14
      at runWorker (~/play-bun/node_modules/@zip.js/zip.js/lib/core/codec-pool.js:56:26)
      at ~/play-bun/node_modules/@zip.js/zip.js/lib/core/zip-writer.js:573:24

The problem seems to came here, the url() call return undefined.

Context

  • Environment: Darwin 23.0.0 arm64 arm
  • bun version: 1.0.25
@gildas-lormeau
Copy link
Owner

gildas-lormeau commented Jan 27, 2024

Hi @ghoullier!

First of all, I'd like to take this opportunity to wish you a happy new year :)

Thanks for reporting the bug, I've reproduced it and fixed it. The next version should be compatible with Bun out of the box. However, it looks like Bun (still) doesn't support Blob URIs (returned by URL.createObjectURL()) or data URIs with workers. The CompressionStream API is missing (but polyfilled) and the crypto API is also buggy.

As a consequence, in order to use workers in Bun you have to call configure and pass the path to z-worker.js. This file must also be in your public folder. See below.

import { configure } from "@zip.js/zip.js";

configure({
  workerScripts: {
    deflate: ["path/to/z-worker.js"],
    inflate: ["path/to/z-worker.js"]
  }
});

@gildas-lormeau
Copy link
Owner

The new version 2.7.33 which should fix this issue is available for download.

@ghoullier
Copy link
Author

Happy new year too gildas 😀

2.7.33 fixed the issue! Thanks!

@gildas-lormeau
Copy link
Owner

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants