I'm trying to extract a 7z file using libarchive and display it in React.
The file name and '_7zOpen !!' are being logged but then it doesn't seem to be running this line: const filesObj = await archive.getFilesObject();
or actually extracting the file.
I'm receiving the following error: Loading Worker from “http://localhost:3000/libarchive.js/dist/worker-bundle.js” was blocked because of a disallowed MIME type (“text/html”).
I added a dist
folder inside public and added the worker-bundle.js file inside it.
I'm following the libArchive ReadMe
How can I solve this and get access to the file? Or how can I work with an alternative to libarchive to extract a 7z file in React?
handleFile.js
import { Archive } from 'libarchive.js/main.js';
Archive.init({
workerUrl: 'libarchive.js/dist/worker-bundle.js'
});
export const handleFile = async () => {
const file = '...'
console.log('file: ', file)
console.log('_7zOpen !! ')
const archive = await Archive.open(file);
console.log('archive: ', archive)
const filesObj = await archive.getFilesObject();
const fileExtracted = await filesObj['...'].extract();
console.log("filesObject: ", fileExtracted)
// const filesArray = await archive.getFilesArray();
// console.log("filesArray: ", filesArray)
return fileExtracted
}