Closed smiles3983 closed 2 years ago
this is the line im executing:
const reader = new zip.ZipReader(new zip.BlobReader(blob));
Did you import zip.js asynchonously and inject Blob
in globalThis
? Here is an example showing how to use a Blob object in Node: https://github.com/gildas-lormeau/zip.js/tree/master/tests/node.
I was able to make it work with blob-polyfill. And then I also had to use jsdom to replace FileReader from window.FileReader
That's interesting, I was not expecting that you would need a FileReader
implementation. What code is forcing you to polyfill it?
I'm meaning that if FileReader
is not needed by zip.js (this is what I expect) but by your code, then you could maybe use Blob#text
or Blob#arrayBuffer
instead.
Note that you don't need to import zip.js asynchronously in Node.js with the version 2.4.5.
I'm moving this issue to the Discussion tab
trying to unit test when I use the BlobReader. I know Blob is a Web-API, and nodejs doesnt have access to it. Ive been able to stub it within my JSX file, but when Zip.js runs, it doesnt appear to have access to my stub. Any ideas how to unit test this?
ReferenceError: Blob is not defined at t (file:///c:/ws/Insight/wordaddin/node_modules/@zip.js/zip.js/lib/z-worker-inline.js:1:86) at file:///c:/ws/Insight/wordaddin/node_modules/@zip.js/zip.js/lib/zip-fs.js:44:1 at ModuleJob.run (node:internal/modules/esm/module_job:185:25) at async Promise.all (index 0) at ESMLoader.import (node:internal/modules/esm/loader:281:24) at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)