I couldn't find a way to read zip content as a chunk from HTTP response.
I provide an example with JSZip library .(I'm open to other libraries if necessary )
const zip = new JSZip();
const readZipCunk = async (chunk)=>{
const ziped = await zip.loadAsync(chunk, { optimizedBinaryString: true })
ziped.forEach((relativePath, file) => {
file.nodeStream().pipe(parser); // parser is not relevant , just demonstrate
//what i do with the "extracted" chunk
});
}
https.get(options, (res) => {
res.on("data",readZipCunk );
})
When the zip file is small it could success but when the filesize is large im getting error. Error: Corrupted zip: can't find the end of central directory
ofc, if i will concat chunks and invoke "readZipCunk " function in the:
response.on('data',(chunk)=>{chunks.push(chunk})
response.on('end',()=>{readZipCunk( Buffer.concat(chunks)}) // it will work
But i must keep the memory low as I can, also I know some information on the zip file like the file name , size , maybe I can use this information and avoid using of request the central directory?