Khaz
Knight
#ZipLib
Does anyone have experience with this utility? I'm having some trouble with its ZipOutputStream compression writing spaces instead of characters. This is the code that I was using:
The FastZip works without a problem, but the regular zip method's files are filled with spaces instead of the characters that are really there. The ProcessFile method is almost a clone of the ZipLib's example CreateZip.
Does anyone have experience with this utility? I'm having some trouble with its ZipOutputStream compression writing spaces instead of characters. This is the code that I was using:
Code:
public static bool ConcatLogFolder()
{
FastZip z = new FastZip();
z.CreateZip( "testzip.zip", "Logs", true, "" );
Crc32 crc = new Crc32();
ZipOutputStream zip = new ZipOutputStream( File.Create( String.Format( "{0}.zip", GetFileName() ) ) );
zip.SetLevel( 9 );
ProcessDirectory( zip, crc, "Logs" );
zip.Finish();
zip.Close();
return true;
}
public static void ProcessDirectory( ZipOutputStream zip, Crc32 crc, string path )
{
string[] files = Directory.GetFiles( path );
string[] subDirs = Directory.GetDirectories( path );
foreach( string filename in files )
ProcessFile( zip, crc, filename );
foreach( string dir in subDirs )
ProcessDirectory( zip, crc, dir );
}
public static void ProcessFile( ZipOutputStream zip, Crc32 crc, string path )
{
FileStream fs = File.OpenRead( path );
byte[] buffer = new byte[fs.Length];
ZipEntry entry = new ZipEntry( ZipEntry.CleanName( path, true ) );
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update( buffer );
entry.Crc = crc.Value;
zip.PutNextEntry( entry );
zip.Write( buffer, 0, buffer.Length );
}