I call an API which returns a buffer data of a .zip file. I want to read files' buffer data which resides inside the .zip file using its buffer data without saving the .zip file. Is it possible?
-
Does this answer your question? Node.js read a file in a zip without unzipping itasync– async2022-06-20 08:44:55 +00:00Commented Jun 20, 2022 at 8:44
-
The two answers rely on a saved .zip files in the system but in my case its working .zip file buffer data. It means that there is no .zip file path only buffer data to work with.T.H.Naseri– T.H.Naseri2022-06-20 08:53:35 +00:00Commented Jun 20, 2022 at 8:53
Add a comment
|
1 Answer
Try the zlib library (its a core node.js library - docs: https://nodejs.org/api/zlib.html#zlib), with this example I took from the documentation
const {unzip } = require('node:zlib');
const buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
unzip(buffer, (err, buffer) => {
if (err) {
console.error('An error occurred:', err);
process.exitCode = 1;
}
console.log(buffer.toString());
});
1 Comment
T.H.Naseri
Thanks for the answer. Can we get the buffers of each file included in zip file after unzipping it? If yes, how?