Zip text but leave the newlines uncompressed

136 Views Asked by At

I have a text file of this structure:

Nice text, text 
More texts and words
Many more sentences
….

Just a bunch of text lines. Now I need to compress the file so that the structure of the file stays the same. Thats is if I read the first line of the compressed file. It should return jumbled/compressed but only of the first line of the original text which is

“ Nice text, text ”

Thats is the compressed file shoud look like this:

;₽73!:228sj
3773!;
Jd7:

To put it shortly: the compeessor should not touch the newline chars in any way!

Is there such an option in any of the zip/tar/rar archivators?

2

There are 2 best solutions below

2
Romeo Ninov On

I do not think anything standard would have such function because compressors are created to work with files, not to inspect files internals. You may write sample program to do this feeding as chunks lines. But consider the fact compressor may produce (as compressed text) new line character. How you will distinguish this from standard newlines?

0
Mark Adler On

No.

No compressor will treat new lines in any special way. Furthermore, compressed output can contain new lines, as they can contain any other byte value, all with approximately equal probability. So you wouldn't be able to parse it into the original lines anyway.

If your objective is to be able to access individual lines randomly, then you will not be able to compress short lines significantly or at all.

You need to say what you are trying to do. Whatever that is, you are way off on the wrong track.