Moin Ahmad Ansari
Moin Ahmad Ansari

Reputation: 19

Unzip single file from zip archive using node.js zlib module

Let say I have a zip archive test.zip which contained two files:

test1.txt and text2.txt

I want to extract only test1.txt using the node inbuilt zlib module.

How to do that?

I don't want to install any package.

Upvotes: 0

Views: 698

Answers (1)

Mark Adler
Mark Adler

Reputation: 112642

You could run a shell command to unzip, assuming that unzip is installed on your system. (It very likely is.)

As far as I can tell, there is no zip functionality within node.js without installing a package.

You can use zlib to help you with the decompression part, but you will have to write your own code to interpret the zip format. You can use zlib.inflateRaw to decompress the raw deflate compressed data of a zip entry. You have to first find where that compressed data starts by reading and interpreting the zip file headers.

The zip format is documented here.

Upvotes: 2

Related Questions