Home > Uncategorized > Unzipping GZIP files on the fly (C#)

Unzipping GZIP files on the fly (C#)

I recently set about writing some code to download a file named pf[1].csv.gz – which was GZIP’ed and creating the corresponding CSV file on disk. Using the ICSharpCode Zip compression library, I used this code:

string strCSVFile = "c:\pf[1].csv";
string strUrl = "http://www.someurl.com/pf[1].csv.gz";
WebClient wc =
new WebClient();
Byte[] bZip = wc.DownloadData(strUrl);
MemoryStream msZip =
new MemoryStream(bZip);
GZipInputStream gzisZip =
new GZipInputStream(msZip);
FileStream fsOutput =
new FileStream(strCSVFile,FileMode.Create);
Byte[] bCSV =
new Byte[Byte.MaxValue];
Int32 iReadCount = Byte.MaxValue;
   iReadCount = gzisZip.Read(bCSV,0,iReadCount);

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: