-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to extract ZIP archive using zlib module? #2385
Comments
Node.js core doesn’t support the full |
@addaleax Thanks for the reply... So this answer is definitely wrong? The OP says "zlib does not support zip files from what i read? Can you please confirm?" and then the response comes: "They support, use deflate api or create a unzip class object and use the api. Read and try with deflate option for start and then dig deeper" and the OP accepted it as an answer, meaning probably they somehow did it? And also am I understanding correctly this issue: node/#26332? Is it talking about ZIP inflate support? I'm not looking for full support (like some fancy file structure explorer etc). I can write low-level things like ZIP header check, I can locate file start and file end, but the main question is can I somehow use ZLIB module to decode/decompress/inflate/unzip the buffer that represents the file content once I find its boundaries? For example suppose I have a ZIP file and it contains some files, then I manually parse ZIP header and chunks or whatever there is, and I locate the start position and length of a buffer representing the file I want to extract. Then I Thanks in advance. |
I mean, it sounds like you have a pretty good understanding of what the zlib API provides – support for deflate/inflate, but not for the .zip file format.
Yes, as long as the compression method that is used is actually deflate. I think that’s a reasonable assumption, though.
Yes, I think that should work. 👍 |
good to know. thank you |
@addaleax, are there technical (or political) reasons for not supporting ZIP archives with node standard library? Or is it just a matter of not having gotten around to it as of yet? |
@maletor I guess the question is, why do that when there’s userland libraries out there that do the same thing? The .zip format comes with a decent amount complexity on top of zlib, so I think having npm packages instead is a good choice. |
@addaleax one reason is that requiring userland packages means that a small portable script can't be shipped without requiring client side install; being able to rely on node packages for the most common formats and functions means you can run anywhere node is installed without extra client side setup |
How to use zlib module to extract files from a ZIP archive? Is it possible using the builting zlib module, or do I have to parse ZIP file manually? Using an external NPM module is not an option.
This is my attempt:
And I get the following error
Sample ZIP file: https://codeload.github.com/nodejs/help/zip/master
But also it throws error with any ZIP file.
What I would like is to list the files that are in the archive and to extract a specific file to some given location. How to do that?
Thanks.
The text was updated successfully, but these errors were encountered: