2

I am aware of GZipStream but, it appears to only support .gz compression. Does anyone know of a way to compress a file to .Z compression format from within C#? (I have also seen the ChilKat commercial library that is available but, I can't spend any money on this effort).

Thanks in advance for whatever help you can provide.

rogdawg
  • 687
  • 3
  • 11
  • 33
  • Out of the box in the .NET framework, no I am not aware of any class of any shipped assembly that does that. You are going to have to go 3rd party with this somehow. – vcsjones Mar 08 '13 at 18:45
  • Something in managed code or simply a wrapper? – Meirion Hughes Mar 08 '13 at 18:45
  • 2
    http://stackoverflow.com/questions/4544066/is-there-a-library-to-unzip-z-files-using-vb-net and http://stackoverflow.com/questions/801473/extracting-a-tar-z-file-in-c-sharp and as Z is LZW: http://stackoverflow.com/questions/8713850/lzw-data-compression – Meirion Hughes Mar 08 '13 at 18:49
  • 1
    I have seen the posts you linked to but, looking at it again, I just read a sentence that I missed before: "but I am not sure if they support .Z archives. I know that 7-Zip does" So, 7-Zip DOES support .Z. Thanks for that...also "and as Z is LZW"...I didn't know that. So, I believe I have my answers...I'll dive into those. Thanks very much. – rogdawg Mar 08 '13 at 19:09
  • One note: 7Zip only supports unpacking of .Z files. It does not support packing .Z files. – rogdawg Mar 08 '13 at 21:06
  • Only http://stackoverflow.com/questions/8713850/lzw-data-compression is a duplicate, which also asks about compression to the .Z format. The other two are asking about decompressing the .Z format, which is much easier to come by. gzip decompresses the .Z format, for example. But it does not compress to it. The note at the top of the answer is wrong. This question does not have an answer there (http://stackoverflow.com/questions/4544066/is-there-a-library-to-unzip-z-files-using-vb-net). – Mark Adler Mar 08 '13 at 22:26
  • This isn't a duplicate because the question specifically asks how to create .z files, but the lined answer only discusses opening those files and the code that is provided only supports unzipping. – dylanT Oct 25 '18 at 06:05

1 Answers1

0

.Z files are generated by the unix compress command; the contents of which are probably compressed with LZW. See compress. So what you really want is LZW compression/decompression.

You could use the Sharp-LZW library, or alternatively you could use the code from Rossetta Code

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
  • 1
    Both these solutions are great for source files that are text...I am trying to compress a file that is binary data...MY program has to take binary data, byteswap it, then compress it to .Z. These solutions rely on a string data source. So, I will have to come up with some other solution. Thank you for your response. – rogdawg Mar 15 '13 at 17:50