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
Post a Comment