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

Was it helpful?

Solution

Why don't you use a simple header to determine block boundaries? Consider this:

  1. Read fixed amount of data from input into a buffer (say 32 KiB)
  2. Compress that buffer with a "freshly created" deflate stream (underlying compression algorithm of ZLIB).
  3. Write compressed size to output stream
  4. Write compressed data to output stream
  5. Go to step 1 until you reach end-of-file.

Pros:

  1. You can decompress any block even in multi-threaded fashion.
  2. Data corruption only limited to corrupted block. Rest of data can be restored.

Cons:

  1. You loss most of contextual information (similarities between data). So, you will have lower compression ratio.
  2. You need slightly more work.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top