2

I wish to compress a given string with a pre-existing header retrieved from an already compressed file in an archive (a local file header).

I have attempted to look at zlib and while their compression/decompressing works nicely I can not find an option to set the compression header.

I want to avoid decompressing a file, add a string to the file, and then re-compress the file. Instead I simply want to "append" a given string to a given compressed file.

I have made attempts using the existing Zipfile module in Python, here I have tried to modify the Zipfile module to deal with a pre-set header, however from this I can conclude that the Zipfile module relies too heavily on the zlib library for this to be possible.

While my attempts have been in Python I am happy using any programming language.

5
  • 1
    "I have made attempts" - where are they, and what's the problem with them. Commented Jul 13, 2016 at 11:50
  • Edited to reflect above comment. Commented Jul 13, 2016 at 12:00
  • What is the actual problem you're trying to solve? Commented Jul 13, 2016 at 12:07
  • Basically pattern matching in a compressed file for a given search word. Does that answer your question? Commented Jul 13, 2016 at 12:41
  • Appending a string to a compressed file has no relation to "pattern matching in a compressed file for a given search word". Commented Jul 14, 2016 at 8:43

1 Answer 1

1

What you want to do is more complicated than you think. However the code has already been written. Look at gzlog.h and gzlog.c in the examples directory of the zlib distribution.

Sign up to request clarification or add additional context in comments.

4 Comments

It seems that this is used to write to log files and not to existing files such as a compressed document? Am I misunderstanding something here? An example of use would be greatly appreciated.
"I want to avoid decompressing a file, add a string to the file, and then re-compress the file. Instead I simply want to "append" a given string to a given compressed file." That is exactly what gzlog does, given that you used gzlog to make the compressed file. It avoids having to decompress or recompress. If you want to append to an unprepared gzip file, then you need to decompress the whole thing first, but you don't need to recompress it, like gzappend.c does (also found in examples in zlib).
Please correct me if I am wrong, but from this I gather that it should be impossible to "append" to a text file that has been compressed previously only using that given file's compression header, unless the file given was compressed using gzlog? That being without decompressing and recompressing.
You need to read my last comment again. It is possible to append to a deflate-compressed stream with decompressing but without recompressing. You keep talking about a "compression header" which doesn't have any meaning here. The entire unprepared, compressed file must be processed to be able to append to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.