April 5th, 2010, 10:18 AM
I need to create a byte array, with the zip of multiple byte arrays. I don't want to generate files during the process. I have coded what is displayed next:
FileStream tempFileStream = new FileStream(@"C:\test.zip", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
Stream compressedContents = new MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(compressedContents);
for (int i = 0; i < attachments.Count; i++) //attachments -> byte 
ZipEntry entry = new ZipEntry(attachsNames);
entry.DateTime = DateTime.Now;
entry.Size = attachments.Length;
zipOutput.Write(attachments, 0, attachments.Length);
byte buffer = new byte[compressedContents.Length];
compressedContents.Read(buffer, 0, (int)compressedContents.Length);
tempFileStream.Write(buffer, 0, (int)compressedContents.Length);
The file defined is only for testing purposes. When I try to open it, appears the usual error when a file is broken: "can not open test.zip as an archive".
If variable compressedContents is directly a FileStream, instead of a MemoryStream, the test file is created correctly. The problem may be on the way I use the memoryStream or the buffer...But it seems all correct for me!! Any solutions for this?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!