usability - compressed filename - encoding #292

Open
opened 2026-01-29 22:09:38 +00:00 by claunia · 1 comment
Owner

Originally created by @thanasisCoung on GitHub (May 2, 2018).

I used the sharpcompress 0.20.0 today against a thousand zips with 1 GB each searching for specific files for extracting info on the fly. It works. Excellent. 👍

I want to thank you and make two observations

-observation 1
If i want to use the compressed filename i have to extract it from reader.Entry.Key. Maybe something like reader.Entry.Key.Name & reader.Entry.Key.FullName
-example

        using (Stream stream = File.OpenRead(zipFileFullName))
        using (var reader = ReaderFactory.Open(stream))
        {
            while (reader.MoveToNextEntry())
            {
                if (Regex.IsMatch(reader.Entry.Key, repTemplate))
                {
                    if (reader.Entry.Key.IndexOf('/') != -1)
                    {
                        using (Stream rep = reader.OpenEntryStream())
                            await RouteStream(rep, repType, reader.Entry.Key.Split('/')[1]);        
                    }
                    else
                        using (Stream rep = reader.OpenEntryStream())
                            await RouteStream(rep, repType, reader.Entry.Key);
                }
            }

-observation 2
can't find a way to open a stream with an enconding so i have to re-open
using (StreamReader rep737 = new StreamReader(rep, Encoding.GetEncoding("ibm737")))
--my fault you got it
ReaderOptions readerOptions = new ReaderOptions() { ArchiveEncoding=new ArchiveEncoding() {Forced= Encoding.GetEncoding("ibm737") } };

Originally created by @thanasisCoung on GitHub (May 2, 2018). I used the sharpcompress 0.20.0 today against a thousand zips with 1 GB each searching for specific files for extracting info on the fly. It works. Excellent. 👍 I want to thank you and make two observations -observation 1 If i want to use the compressed filename i have to extract it from reader.Entry.Key. Maybe something like reader.Entry.Key.Name & reader.Entry.Key.FullName -example using (Stream stream = File.OpenRead(zipFileFullName)) using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (Regex.IsMatch(reader.Entry.Key, repTemplate)) { if (reader.Entry.Key.IndexOf('/') != -1) { using (Stream rep = reader.OpenEntryStream()) await RouteStream(rep, repType, reader.Entry.Key.Split('/')[1]); } else using (Stream rep = reader.OpenEntryStream()) await RouteStream(rep, repType, reader.Entry.Key); } } -observation 2 can't find a way to open a stream with an enconding so i have to re-open ` using (StreamReader rep737 = new StreamReader(rep, Encoding.GetEncoding("ibm737")))` --my fault you got it `ReaderOptions readerOptions = new ReaderOptions() { ArchiveEncoding=new ArchiveEncoding() {Forced= Encoding.GetEncoding("ibm737") } };`
Author
Owner

@adamhathcock commented on GitHub (May 5, 2018):

Thanks for the feedback!

I went for the name "Key" because the key isn't necessarily supposed to mean a filepath in an archive. I understand this is usually the case though. You can contribute some extension methods for better handling file names if you'd like.

I'm about to release some fixes to zip encoding as someone pointed out the proper encoding: https://github.com/adamhathcock/sharpcompress/pull/363/files

@adamhathcock commented on GitHub (May 5, 2018): Thanks for the feedback! I went for the name "Key" because the key isn't necessarily supposed to mean a filepath in an archive. I understand this is usually the case though. You can contribute some extension methods for better handling file names if you'd like. I'm about to release some fixes to zip encoding as someone pointed out the proper encoding: https://github.com/adamhathcock/sharpcompress/pull/363/files
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#292