Implement zip decompression in the memory

Source: Internet
Author: User

I recently completed a job on decompression and gotSource codeIs based on the file format. It does not meet the development needs of the project, so it is only modified on the basis of the original. At the beginning, I felt very troublesome.CodeAt the beginning, I always wanted to understand how to modify and view data step by step.AlgorithmLater, I found that the time was really not enough, and it took only two days to complete the modification and debugging. I just figured out the process and some interface descriptions and found that at the end, after modification at the source and end (that is, the part that reads the file and the output file), you can. After all, the cool person who writes this algorithm, the code function is well encapsulated.

During decompression

# Define get_byte () (inptr <insize? Inbuf [inptr ++]: fill_inbuf (0 ));
# Define try_byte () (inptr <insize? Inbuf [inptr ++]: fill_inbuf (1 ));

These two macro definitions are used to analyze and work the compressed package files. From the above, we can see that when the data in inbuf [] is read, we will immediately update the data in inbuf, so we think inbuf is very big, so we don't need to update it from the new one, so all the data is in the memory, so I have slightly modified this macro.

# Define get_byte () (inptr <insize? Inbuf [inptr ++]: do_exit (1 ))

Do_exit () is used to release the memory.

The corresponding output is also very simple. If the original output is to a file, we only need to allocate a memory space and output the original output to the memcpy (DES, SRC, length) part of the file) to the new, it will be implemented accordingly.

The definition of macro is as follows:

# Define put_ubyte (c) {window [outcnt ++] = (UCH) (c); If (outcnt = wsize )/
Flush_window ();}

Modify flush_window (); To implement the output in the memory.

However, during compression

The Modification Principle is almost the same as the decompression time.

But the changes are different.

It is mainly to modify the file_read (BUF, size) method. The output is also consistent with the above class to view the macro definition.

# Define put_byte (c) {outbuf [outcnt ++] = (UCH) (c); If (outcnt = outbufsiz )/
Flush_outbuf ();}

Modify flush_outbuf ();

Use the source code (the original region in www.zip. org
Can be obtained

If you have a better solution, you can reply in the message. Or alajl@hotmail.com

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.