User (Old forums)MemberFebruary 7, 2008 at 10:08 amPost count: 23064
I have a zip file on disk. Some of the files in the zip are ‘stored’ having 0% compression. I have been asked to rezip the file and compress the candidate files with Real Time.
I guess the question is this.
Since Real Time doesn’t support ‘Stored’, I can pull an Abstract File array using standard Xceed.zip.ZipArchive
AbstractFile myArray = zip.GetFiles(“*.*”);
Is it now possible to iterate through this array and write it back out with
the Real Time ZipWriter?
I tried the below code but since the Abstract file is not a .zip file, it doesn’t work.
Alternative suggestions welcome.
newZipStream = new FileStream(@”c:\” + item.ItemName + “.test.zip”, FileMode.Create);
using (zipWriter = new Xceed.Zip.ReaderWriter.ZipWriter(newZipStream))
Xceed.Zip.ZipArchive zip = new ZipArchive(new Xceed.FileSystem.DiskFile(zipPath));
Xceed.FileSystem.AbstractFile zipContentFiles = zip.GetFiles(true, “*.*”);
foreach (Xceed.FileSystem.AbstractFile zipContentFile in zipContentFiles)//iterate array
zipContentStream = zipContentFile.OpenRead();
Xceed.Zip.ReaderWriter.ZipReader zReadIn = new Xceed.Zip.ReaderWriter.ZipReader(zipContentStream);
Xceed.Zip.ReaderWriter.ZipItemLocalHeader newHeader = newXceed.Zip.ReaderWriter.ZipItemLocalHeader(zipContentFile.FullName, Xceed.Compression.CompressionMethod.Deflated, Xceed.Compression.CompressionLevel.Normal);
byte buffer = new byte;
int read = 0;
while ((read = zReadIn.ReadItemData(buffer, 0, buffer.Length)) > 0)
zipWriter.WriteItemData(buffer, 0, read);
Imported from legacy forums. Posted by Patrick (had 2926 views)User (Old forums)MemberFebruary 13, 2008 at 4:35 pmPost count: 23064
You don’t specify the exception that you get, so I’m not sure why this does not work, but one thing is sure, you don’t need to use the ZipReader to get the content of the file into memory to be able to feed it back to the ZipWriter. You can do it directly through a stream.
Note that the files returned by the ZipArchive.GetFiles are ZippedFile’s, so when reading from them through the OpenRead() method, it decompresses them.
I tested the code below, and it works fine :
using( FileStream fileStream = new FileStream( @”D:\temp\zipWriter.zip”, FileMode.Create ) )
using( ZipWriter zipWriter = new ZipWriter( fileStream ) )
ZipArchive archive = new ZipArchive( new DiskFile( @”D:\temp\audio.zip” ) );
AbstractFile files = archive.GetFiles( true );
foreach( AbstractFile file in files )
zipWriter.WriteItemLocalHeader( new ZipItemLocalHeader( file.Name, Xceed.Compression.CompressionMethod.Deflated, Xceed.Compression.CompressionLevel.Normal ) );
using( Stream stream = file.OpenRead() )
byte buffer = new byte[ 32768 ];
int bytesRead = 0;
while( ( bytesRead = stream.Read( buffer, 0, buffer.Length ) ) > 0 )
zipWriter.WriteItemData( buffer, 0, bytesRead );
Imported from legacy forums. Posted by André (had 3619 views)
- You must be logged in to reply to this topic.