I'm using reactjs and chrome.
I have built a webpage where I can upload an archive file and I want to do some further work on the file.
When the archive file is 7zip, I am using this library node-7z to try to extract a single file from the it.
The official documentation in the link suggests to use it like this:
// myStream is a Readable stream
const myStream = Seven.extractFull('./archive.7z', './output/dir/', {
$progress: true
})
My code (part of it):
import sevenBin from '7zip-bin'
import Seven from 'node-7z'
const _7zOpen = async (f) => {
console.log('_7zOpen !! ', f)
// myStream is a Readable stream
const myStream = Seven.extractFull(f.path, './output/dir/', {
$progress: true
})
myStream.on('data', function (data) {
console.log(data)
})
myStream.on('progress', function (progress) {
console.log(progress)
})
}
where the input f is a file object:
_7zOpen !!
File {path: 'CE027001-120011101924-T100.7z',
name: 'CE027001-120011101924-T100.7z',
lastModified: 1599377977254,
lastModifiedDate: Sun Sep 06 2020 16:39:37 GMT+0900, webkitRelativePath: '', …}
lastModified: 1599377977254
lastModifiedDate: Sun Sep 06 2020 16:39:37 GMT+0900 {}
name: "CE027001-120011101924-T100.7z"
path: "CE027001-120011101924-T100.7z"
size: 75602083
type: "application/x-7z-compressed"
webkitRelativePath: ""
[[Prototype]]: File
It gives an error:
Unhandled Rejection (TypeError): spawn is not a function
▼ 3 stack frames were expanded.
run
node_modules/node-7z/src/lifecycle.js:74
(anonymous function)
node_modules/node-7z/src/main.js:55
extractFull
node_modules/node-7z/src/commands.js:27
▲ 3 stack frames were expanded.
_7zOpen
src/components/shared/utils/compressedFileHandler.js:56
53 |
54 |
55 | const pathTo7zip = sevenBin.path7za;
> 56 | const seven = Seven.extractFull(f.path, './output/dir/', {
| ^ 57 | $bin: pathTo7zip
58 | });
59 |
I tried another way:
const _7zOpen = async (f) => {
console.log('_7zOpen !! ', f)
const pathTo7zip = sevenBin.path7za;
const seven = Seven.extractFull(f.path, './output/dir/', {
$bin: pathTo7zip
});
}
which gives the same error message when the file is uploaded.
It could be that the f.path is not valid.
How can I find the correct path to feed to the function?