You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you very much for developing ZipStorer. I have used it in several apps and until now I haven't encountered a problem.
In my last project I needed check a content of archive before add new files to avoid duplicate file names in that archive. I find out if I read an archive content and then I add no files into it to avoid duplicates causes an archive corruption.
See my test code. After first run a new archive is created. After second run an existing archive is opened and after check for duplicate file names in archive no files are added. And after that the whole archive is corrupted! And I opened only an existing archive, then I read its content, I wrote down no files and in the end I close it.
Do you have an idea where the problem might be?
const string archiveFilePath = @"C:\Temp\test.zip";
var archiveFileExists = File.Exists(archiveFilePath);
using (var zipArchive = archiveFileExists
? ZipStorer.Open(archiveFilePath, FileAccess.ReadWrite)
: ZipStorer.Create(archiveFilePath, "TestArchive"))
{
var zipFileEntries = archiveFileExists
? zipArchive.ReadCentralDir()
: new List<ZipStorer.ZipFileEntry>();
for (int i = 0; i < 10; i++)
{
if (zipFileEntries.Any(e => e.FilenameInZip == $"TestFile_{i + 1:00}.txt")) continue;
using (var memoryStream = new MemoryStream())
using (var streamWriter = new StreamWriter(memoryStream))
{
streamWriter.WriteLine("TEST!");
streamWriter.Flush();
memoryStream.Seek(0, SeekOrigin.Begin);
zipArchive.AddStream(ZipStorer.Compression.Deflate, $"TestFile_{i + 1:00}.txt", memoryStream,
DateTime.Now, string.Empty);
}
}
}
The text was updated successfully, but these errors were encountered:
I have tried it and I can confirm that it works. BUT it was expected, because the ZIP file remained intact ;-)
Unfortunately, I found an another bug. I have used the same code snippet.
Steps to reproduce:
run code for the first time
with external tool delete any file from test.zip archive
run code for the second time
with external tool open test.zip and the last file in the archive will be corrupted (bad CRC)!!!
Thank you very much for developing ZipStorer. I have used it in several apps and until now I haven't encountered a problem.
In my last project I needed check a content of archive before add new files to avoid duplicate file names in that archive. I find out if I read an archive content and then I add no files into it to avoid duplicates causes an archive corruption.
See my test code. After first run a new archive is created. After second run an existing archive is opened and after check for duplicate file names in archive no files are added. And after that the whole archive is corrupted! And I opened only an existing archive, then I read its content, I wrote down no files and in the end I close it.
Do you have an idea where the problem might be?
The text was updated successfully, but these errors were encountered: