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