Search for entries in zip archive #479

Open
opened 2026-01-29 22:12:44 +00:00 by claunia · 0 comments
Owner

Originally created by @neumatho on GitHub (Sep 26, 2021).

If you open an entry in a zip archive and while you have it opened, search for another entry, the first entry is not complete. Here is an example:

using System;
using System.IO;
using System.Linq;
using SharpCompress.Archives.Zip;

namespace Archive
{
	class Program
	{
		static void Main(string[] args)
		{
			using (FileStream fs = new FileStream(@"P:\\m\\rw\\sfx2.angel_harp.zip", FileMode.Open))
			{
				ZipArchive archive = ZipArchive.Open(fs);

				ZipArchiveEntry entry = archive.Entries.FirstOrDefault(e => e.Key == "SOAMC/SOAMC_AMIGA/SoundFX_2.0/Roman_Werner/sfx2.angel_harp");
				using (Stream s = entry.OpenEntryStream())
				{
					ZipArchiveEntry entry1 = archive.Entries.FirstOrDefault(e => e.Key == "SOAMC/SOAMC_AMIGA/SoundFX_2.0/Roman_Werner/sfx2.angel_harp.txt");

					using (MemoryStream ms = new MemoryStream())
					{
						s.CopyTo(ms);
						long len = ms.Length;
					}
				}
			}
		}
	}
}

It this case, the len variable is zero, which means nothing has been copied to the MemoryStream. If you uncomment the entry1 search (which do not find anything), then it works fine. Also if I change the entry1 search to search for the same entry (or some other entry that does exists), it also work. It seems to fail, if the search did not find anything.

I have attached the test archive, but I guess you can use any archive.

sfx2.angel_harp.zip

Originally created by @neumatho on GitHub (Sep 26, 2021). If you open an entry in a zip archive and while you have it opened, search for another entry, the first entry is not complete. Here is an example: ``` using System; using System.IO; using System.Linq; using SharpCompress.Archives.Zip; namespace Archive { class Program { static void Main(string[] args) { using (FileStream fs = new FileStream(@"P:\\m\\rw\\sfx2.angel_harp.zip", FileMode.Open)) { ZipArchive archive = ZipArchive.Open(fs); ZipArchiveEntry entry = archive.Entries.FirstOrDefault(e => e.Key == "SOAMC/SOAMC_AMIGA/SoundFX_2.0/Roman_Werner/sfx2.angel_harp"); using (Stream s = entry.OpenEntryStream()) { ZipArchiveEntry entry1 = archive.Entries.FirstOrDefault(e => e.Key == "SOAMC/SOAMC_AMIGA/SoundFX_2.0/Roman_Werner/sfx2.angel_harp.txt"); using (MemoryStream ms = new MemoryStream()) { s.CopyTo(ms); long len = ms.Length; } } } } } } ``` It this case, the len variable is zero, which means nothing has been copied to the MemoryStream. If you uncomment the entry1 search (which do not find anything), then it works fine. Also if I change the entry1 search to search for the same entry (or some other entry that does exists), it also work. It seems to fail, if the search did not find anything. I have attached the test archive, but I guess you can use any archive. [sfx2.angel_harp.zip](https://github.com/adamhathcock/sharpcompress/files/7230918/sfx2.angel_harp.zip)
claunia added the question label 2026-01-29 22:12:44 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#479