Question
I have a X bytes file. And I want to compress it in block of size 32Kb, for example. Is there any lib that Can I do this?
I used Zlib for Delphi but I just can compress a full file in new compressed file.
Tranks a lot, Pedro
Solution
Why don't you use a simple header to determine block boundaries? Consider this:
- Read fixed amount of data from input into a buffer (say 32 KiB)
- Compress that buffer with a "freshly created" deflate stream (underlying compression algorithm of ZLIB).
- Write compressed size to output stream
- Write compressed data to output stream
- Go to step 1 until you reach end-of-file.
Pros:
- You can decompress any block even in multi-threaded fashion.
- Data corruption only limited to corrupted block. Rest of data can be restored.
Cons:
- You loss most of contextual information (similarities between data). So, you will have lower compression ratio.
- You need slightly more work.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow