DotNetZip will do what you want, but I understand your concern about legal approval.
On the side of the note. It may be useful for you to navigate the legal jungle associated with obtaining an open source library approved for use by the company in order to understand what exactly is happening. But I will leave it to you.
Returning to its own ... DotNetZip is pretty fully shown, and it handles a number of scripts that you probably don't need. Like Unicode file names and comments that set timestamps and permissions for selected files, getting timestamps of zip files created on older Unix systems, split archives, encrypted archives, 2gb files or self-extracting archives, etc. Etc. Etc. Many zip files use none of these things.
DotNetZip also does events and zip updates and zip creation - all the code associated with these things is probably not of interest to you if you are limited only by the requirements that you described in your question.
You could, however, grab the DotNetZip code and use it to help you roll back your own solution. If you limit yourself to reading zip files ONLY and are not dealing with all possible special cases, the zip format is not difficult to parse.
here's how to do it:
open the zip file using new FileStream() or File.Open . You need a FileStream object.
Read 4 bytes. Make sure this is the zip-entry header descriptor. (0x04034b50) In the file, the order in which you find these bytes is 50 4b 03 04.
if you find a match, you are in business.
- at offset 14 is a 4-byte CRC. Take it. (Same byte order as above)
- at an offset of 18 - 4-byte length of the compressed drop. take it. (H)
- at offset 22, the 4-byte length of UNcompressed blob. take it. (U)
- at 26 is a byte length of 2 bytes. get it (L)
- at 28 is the length of 2 bytes of the "additional field". get it (E)
Besides the extra field, at offset 30, this is the actual file name. read L bytes for the file name and call System.Text.Encoding.ASCII.GetString (). The result will include the directory path, with backslashes replaced with a slash (unix style). String.Replace () slashes.
after the file name is added to the additional field - find E bytes to go beyond it. You can basically ignore this. This is where the compressed data begins.
Open System.IO.DeflateStream () in a zip FileStream using CompressionMode.Decompress and using the current FileStream offset as input. open a new FileStream for output, the path to the file that you read in step 3. in a loop, call inflater.Read (). and output.Write () to write the unpacked DeflateStream output to a file system file with the correct name. You will need to stop reading from DeflateStream when you read exactly U (uncompressed) bytes.
Check the uncompressed size (U) for the data you actually wrote out from DeflateStream (after compression). They must match.
If you're interested, you can check the CRC output for what was in the header.
go to step 2 to find the next entry in the file.
The most difficult part is step 3. The working code for this is easy to find in this source module , find the ReadHeader method.
source share