cthackers / adm-zip

A Javascript implementation of zip for nodejs. Allows user to create or extract zip files both in memory or to/from disk
MIT License
1.99k stars 366 forks source link

Error: Invalid CEN header (bad signature) #442

Open nitinmagdumvista opened 1 year ago

nitinmagdumvista commented 1 year ago

I am getting zip response from a external service which contains multiple files through that zip response i want to get all the files and send to another http post request but i am getting Error: Invalid CEN header (bad signature)

const authStr =Bearer ${token}; const reqBody = logoSignature; const composerUrl = this.configService.getConfiguration('COMPOSER_URL'); const axiosPostConfig: AxiosRequestConfig = { method: 'post', url: composerUrl, headers: { Authorization: authStr, }, data: reqBody, }; let composerServiceResponse = await Utility.apiCall( axiosPostConfig, executionLog, ); console.log('composerServiceResponse', composerServiceResponse); const buffer = Buffer.from(composerServiceResponse,'binary'); const zip = new AdmZip(buffer); const entries = zip.getEntries(); for (let entry of entries) { const buffer = entry.getData(); console.log( 'File: ' + entry.entryName + ', length (bytes): ' + buffer.length + ', contents: ' + buffer.toString('utf-8'), ); }

nitinmagdumvista commented 1 year ago

https://stackoverflow.com/questions/45661857/extract-uploaded-file-using-adm-zip

same kind of response i am getting from the API which returning zip file

cthackers commented 1 year ago

i think you need to add responseType: 'arraybuffer', to your AxiosRequestConfig

Thykof commented 3 weeks ago

Hi, I have the same error on a AWS lambda. It works well in local though