node.js - Node https get file from url and unzip -


i using node https/http module download file. code looks this:

https.get(url) .on('response', (response) => {     response.pipe(fs.createwritestream(datadir + filename)) } 

in next step use unzip module unzip file.

fs.createreadstream(datadir + filename) .pipe(unzip.extract({path: datadir})) .on('close', () => { } .on('error', () => { catch error} 

for cases, works well. however, unzip module returns error:

error: invalid signature: 0x6d74683c 

the issue can notice file name. grab filename url. last parameter of url. however, in cases, exact filename different 1 shown in url. instance:

https://github.com/request/request/archive/master.zip 

the name shown in url master.zip when download name request-master.zip.

is actual problem? if so, how can solve it?

the filename symptom rather root cause. unzip module unmaintained , has many open issues. blame , should not used, regardless.

try out decompress or yauzl instead. also, since attempting extract archive in stream, may want read how not possible.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -