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;
while(iReadCount>0)
{
iReadCount = gzisZip.Read(bCSV,0,iReadCount);
fsOutput.Write(bCSV,0,iReadCount);
}
fsOutput.Close();
gzisZip.Close();
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback