am trying to add a file to an existing archive using the following code. When run no errors or exceptions are shown but no files are added to the archive either. Any ideas why?
using (FileStream fileStream = File.Open(archivePath, FileMode.Open, FileAccess.ReadWrite))
using (ZipOutputStream zipToWrite = new ZipOutputStream(fileStream))
{
zipToWrite.SetLevel(9);
using (FileStream newFileStream = File.OpenRead(sourceFiles[0]))
{
byte[] byteBuffer = new byte[newFileStream.Length - 1];
newFileStream.Read(byteBuffer, 0, byteBuffer.Length);
ZipEntry entry = new ZipEntry(sourceFiles[0]);
zipToWrite.PutNextEntry(entry);
zipToWrite.Write(byteBuffer, 0, byteBuffer.Length);
zipToWrite.CloseEntry();
zipToWrite.Close();
zipToWrite.Finish();
}
}
From Codeproject someone used this code. Only difference is close and finish otherway around and the write part:
BTW:
This is incorrect, the size is newFileStream.length else the Read goes wrong. You have an array and you make it for example 10-1 is 9 bytes long, from 0 to 8.
But your reading from 0 to 9...