zip-archive and rar-archive have different folder separators #433

Closed
opened 2026-01-29 22:11:59 +00:00 by claunia · 2 comments
Owner

Originally created by @daniilzaonegin on GitHub (Jan 15, 2021).

Hi!
Is it alright, that library returns different folder separators for rar and zip?
For example

class Program
    {
        static void Main(string[] args)
        {
            using (Stream stream = File.OpenRead("c:\\temp\\HeliosLogs.rar"))
            using (IArchive archive = ArchiveFactory.Open(stream))
            {
                foreach (IArchiveEntry entry in archive.Entries)
                {
                    Console.WriteLine($"EntryKey:{entry.Key}");
                }
            }

            using (Stream stream = File.OpenRead("c:\\temp\\HeliosLogs.zip"))
            using (IArchive archive = ArchiveFactory.Open(stream))
            {
                foreach (IArchiveEntry entry in archive.Entries)
                {
                    Console.WriteLine($"EntryKey:{entry.Key}");
                }
            }

        }
    }

This program returns

image

We have a solution, that opens archive and shows tree-structure to the user with folders and files.
And I had to handle this case, because we split entry.Key either by "\" or by "/" for building tree structure.
I think library should return unified folder separators independent of archive type.

Originally created by @daniilzaonegin on GitHub (Jan 15, 2021). Hi! Is it alright, that library returns different folder separators for rar and zip? For example ```c# class Program { static void Main(string[] args) { using (Stream stream = File.OpenRead("c:\\temp\\HeliosLogs.rar")) using (IArchive archive = ArchiveFactory.Open(stream)) { foreach (IArchiveEntry entry in archive.Entries) { Console.WriteLine($"EntryKey:{entry.Key}"); } } using (Stream stream = File.OpenRead("c:\\temp\\HeliosLogs.zip")) using (IArchive archive = ArchiveFactory.Open(stream)) { foreach (IArchiveEntry entry in archive.Entries) { Console.WriteLine($"EntryKey:{entry.Key}"); } } } } ``` This program returns ![image](https://user-images.githubusercontent.com/28781018/104738704-eb373580-5756-11eb-8f81-d125231e9641.png) We have a solution, that opens archive and shows tree-structure to the user with folders and files. And I had to handle this case, because we split entry.Key either by "\\" or by "/" for building tree structure. I think library should return unified folder separators independent of archive type.
Author
Owner

@adamhathcock commented on GitHub (Jan 15, 2021):

Entry.Key is a string that comes directly from the archive. It's not interpreted as a file path. The Write extension methods do this. This library is not intended to be a high level API to do what you're asking.

@adamhathcock commented on GitHub (Jan 15, 2021): Entry.Key is a string that comes directly from the archive. It's not interpreted as a file path. The `Write` extension methods do this. This library is not intended to be a high level API to do what you're asking.
Author
Owner

@daniilzaonegin commented on GitHub (Jan 15, 2021):

Okay, thank you! Then I will rewrite my code. First better extract all files from archive to some temporary folder and then build a tree-structure for the user based on this folder.

@daniilzaonegin commented on GitHub (Jan 15, 2021): Okay, thank you! Then I will rewrite my code. First better extract all files from archive to some temporary folder and then build a tree-structure for the user based on this folder.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#433