0

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?

2
  • Does this answer your question? Node.js read a file in a zip without unzipping it Commented 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. Commented Jun 20, 2022 at 8:53

1 Answer 1

2

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());
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Can we get the buffers of each file included in zip file after unzipping it? If yes, how?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.