react native - expo - libarchive.js "Can't find variable: Worker" issue

375 views Asked by At

I am trying to unzip a file which exists in DocumentDirectoryPath but getting the error below:

[Unhandled promise rejection: ReferenceError: Can't find variable: Worker]

  • node_modules\libarchive.js\src\libarchive.js:37:29 in Archive#constructor
  • node_modules\libarchive.js\src\libarchive.js:26:20 in Archive.open

my code below is very simple:

import { Archive } from 'libarchive.js/main.js';

 Archive.init({
      workerUrl: 'libarchive.js/dist/worker-bundle.js'
    });

const sourcePath =
      'file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540testtest%252Ftest/testfile.zip';

    const archive = await Archive.open(sourcePath);

I would appreciate any ideas!

1

There are 1 answers

0
MySqlError On

libarchivejs works with File objects, so instead of passing file path you need to read the file and pass it to Archive.open(fileObject)

here's is examples of reading file

https://github.com/nika-begiashvili/libarchivejs#how-to-use