I am having a problem unzipping a GZIP file...I do not know what process was used to zip it as it comes from a client. However, the file can be sucessfully unzipped using the 7-Zip execuatable. Furthermore, the GZIP file contains several layers of folder structure with the ultimate zipped file residing 5 or 6 layers down the tree. Could that be the problem? Can SharpZipLib handle multiple folder layers?
In the Catch, the Exception is:
Cannot find central directory
Here is the code i am using to attemp to unzip the folders/file:
string currDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6);
ZipFile zf = null;
try {
FileStream fs = File.OpenRead(currDir + "\\TSUSDLYRPT.GZIP");
zf = new ZipFile(fs);
//if (!String.IsNullOrEmpty(password)) {
// zf.Password = password; // AES encrypted entries are handled automatically
//}
foreach (ZipEntry zipEntry in zf) {
if (!zipEntry.IsFile) {
continue; // Ignore directories
}
String entryFileName = zipEntry.Name;
// to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
// Optionally match entrynames against a selection list here to skip as desired.
// The unpacked length is available in the zipEntry.Size property.
byte[ buffer = new byte[4096]; // 4K is optimum
Stream zipStream = zf.GetInputStream(zipEntry);
// Manipulate the output filename here as desired.
String fullZipToPath = Path.Combine(currDir, entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0)
Directory.CreateDirectory(directoryName);
// Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
// of the file, but does not waste memory.
// The "using" will close the stream even if an exception occurs.
using (FileStream streamWriter = File.Create(fullZipToPath)) {
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
catch(Exception ex){}
finally {
if (zf != null) {
zf.IsStreamOwner = true; // Makes close also shut the underlying stream
zf.Close(); // Ensure we release resources
}
}
======================================
The error occurs on the line:
zf = new ZipFile(fs);
The fs object is populated however.
Is there a way for me to attach the actual GZIP file (it is only 3K)? I cannot see how...
Can anyone diagnose this issue without the actual file?
Thanks in advance for all assistance!!