ZipReader, Entry.Key encoding is not UTF8 #117

Open
opened 2026-01-29 22:06:49 +00:00 by claunia · 5 comments
Owner

Originally created by @WilhelmJP on GitHub (Aug 15, 2016).

File names with german umlauts are not unzipped correctly. Therfore searching for a certain key will not work. Here is my code snipped:

        using (var reader = Compress.Reader.Zip.ZipReader.Open(stream, pwd))
        {
            while (reader.MoveToNextEntry())
            {
                if (!reader.Entry.IsDirectory)
                {
                    using (var ms = new MemoryStream())
                    {
                        reader.WriteEntryTo(ms);
                        // if(reader.Entry.Key == "Büro can be found") smile;
                        archive.Add(reader.Entry.Key, ms.ToArray());
                    }
                }
            }
        }

Best
Wilhelm

Originally created by @WilhelmJP on GitHub (Aug 15, 2016). File names with german umlauts are not unzipped correctly. Therfore searching for a certain key will not work. Here is my code snipped: ``` using (var reader = Compress.Reader.Zip.ZipReader.Open(stream, pwd)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { using (var ms = new MemoryStream()) { reader.WriteEntryTo(ms); // if(reader.Entry.Key == "Büro can be found") smile; archive.Add(reader.Entry.Key, ms.ToArray()); } } } } ``` Best Wilhelm
Author
Owner

@adamhathcock commented on GitHub (Aug 20, 2016):

Does it help if you change the ArchiveEncoding class?

@adamhathcock commented on GitHub (Aug 20, 2016): Does it help if you change the ArchiveEncoding class?
Author
Owner

@k003bzw commented on GitHub (Aug 25, 2016):

it also does not work. You can use my project file to test the ArchiveEncoding class.
Project.zip

@k003bzw commented on GitHub (Aug 25, 2016): it also does not work. You can use my project file to test the ArchiveEncoding class. [Project.zip](https://github.com/adamhathcock/sharpcompress/files/436341/Project.zip)
Author
Owner

@adamhathcock commented on GitHub (Sep 27, 2016):

The extract seems to work for me.

I did this:

 using (TestStream stream = new TestStream(File.OpenRead("C:\\Users\\hathcoa\\Downloads\\Project.zip")))
            {
                using (var reader = ReaderFactory.Open(stream))
                {
                    while (reader.MoveToNextEntry())
                    {
                        if (!reader.Entry.IsDirectory)
                        {
                            reader.WriteEntryToDirectory(SCRATCH_FILES_PATH,
                                                         new ExtractionOptions()
                                                         {
                                                             ExtractFullPath = true,
                                                             Overwrite = true
                                                         });
                        }
                    }
                }
                Assert.True(stream.IsDisposed);
            }
@adamhathcock commented on GitHub (Sep 27, 2016): The extract seems to work for me. I did this: ``` using (TestStream stream = new TestStream(File.OpenRead("C:\\Users\\hathcoa\\Downloads\\Project.zip"))) { using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } Assert.True(stream.IsDisposed); } ```
Author
Owner

@adamhathcock commented on GitHub (Sep 27, 2016):

Created an Archive like this and the character was fine:

  using (var archive = ZipArchive.Create())
            {
                using (TestStream stream = new TestStream(File.OpenRead("C:\\Users\\hathcoa\\Downloads\\Project.zip")))
                {
                    using (var reader = ReaderFactory.Open(stream))
                    {
                        while (reader.MoveToNextEntry())
                        {
                            if (!reader.Entry.IsDirectory)
                            {
                                var ms = new MemoryStream();
                                reader.WriteEntryTo(ms);
                                ms.Position = 0;
                                archive.AddEntry(reader.Entry.Key, ms);
                            }
                        }
                    }
                    Assert.True(stream.IsDisposed);
                }
                archive.SaveTo(File.OpenWrite("C:\\Users\\hathcoa\\Downloads\\Project2.zip"));
            }
@adamhathcock commented on GitHub (Sep 27, 2016): Created an Archive like this and the character was fine: ``` using (var archive = ZipArchive.Create()) { using (TestStream stream = new TestStream(File.OpenRead("C:\\Users\\hathcoa\\Downloads\\Project.zip"))) { using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { var ms = new MemoryStream(); reader.WriteEntryTo(ms); ms.Position = 0; archive.AddEntry(reader.Entry.Key, ms); } } } Assert.True(stream.IsDisposed); } archive.SaveTo(File.OpenWrite("C:\\Users\\hathcoa\\Downloads\\Project2.zip")); } ```
Author
Owner

@Wagalv commented on GitHub (Nov 24, 2016):

I had the same issue, but for Portuguese and Spanish characters. To solve this I used the follow code:

using (Stream stream = File.OpenRead(path))
{
SharpCompress.Common.ArchiveEncoding.Default = System.Text.Encoding.GetEncoding(850);
var reader = ReaderFactory.Open(stream, Options.None);
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
reader.WriteEntryToDirectory(savePath, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}

@Wagalv commented on GitHub (Nov 24, 2016): I had the same issue, but for Portuguese and Spanish characters. To solve this I used the follow code: using (Stream stream = File.OpenRead(path)) { SharpCompress.Common.ArchiveEncoding.Default = System.Text.Encoding.GetEncoding(850); var reader = ReaderFactory.Open(stream, Options.None); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(savePath, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } }
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#117