File compression in .NET - for very large files

  • Thread starter Thread starter Amit Dedhia
  • Start date Start date
A

Amit Dedhia

Hi

I want to compress and decomress files. There is GZipStream class
in .Net. However this class requires to allocate buffer equal to the
file length to zip it (at least all sample code I saw were like that).
The file size in my case can be really very large and hence I want
something which does not require to load entire file in memory. Is
there any way?

Thanks and best regards
Amit Dedhia
 
I want to compress and decomress files. There is GZipStream class
in .Net. However this class requires to allocate buffer equal to the
file length to zip it (at least all sample code I saw were like that).
The file size in my case can be really very large and hence I want
something which does not require to load entire file in memory. Is
there any way?

You don't need to read the whole file in. Just copy the data from the
input stream to the GZipStream a chunk (eg 32K) at a time.

I've got a utility class which makes this easier:
http://pobox.com/~skeet/csharp/miscutil
and
http://pobox.com/~skeet/csharp/miscutil/usage/streamutil.html
in particular.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top