Martin
Martin

Reputation: 40573

How to compress multiple files in a GZip file with the GZipStream class?

I am simply looking for a way to compress multiple files in a GZip file with the GZipStream class. Anybody has an idea how to do that?

Upvotes: 8

Views: 10300

Answers (3)

Alex
Alex

Reputation: 65

Old topic, but can help future readers.

I've found this solution (here) which propose to compress/decompress a directory using GZipStream native class.

The example create file list using Directory.GetFiles, but it's easy to change this point and adapt it to your needs.

Note : the compressed file is not a gzip file which can be opened by thrid-party software, but it's a good solution for your app internal management (personally I use it to transfer my application patch files over the network).

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941218

The gzip file format is an archive format, it contains a header and a directory that lists all of the compressed files in the archive. GZipStream merely compresses data written to the stream. The equivalent of one file in the archive, it is not capable of generating the archive format.

A popular solution is SharpZipLib, there are many others.

Upvotes: 3

Andrew Aylett
Andrew Aylett

Reputation: 40690

In general, the gzip format doesn't support multiple files. Traditionally, one bundles multiple files using tar before compressing the result; you probably want to do something similar.

Upvotes: 8

Related Questions