ZipArchive and Encoding

I am trying to make sense of the following piece of documentation:

  • https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive.-ctor?view=net-8.0#system-io-compression-ziparchive-ctor(system-io-stream-system-io-compression-ziparchivemode-system-boolean-system-text-encoding)

Reading the “Remarks” section, in particular this portion:

When you open a zip archive file for reading and entryNameEncoding is
set to a value other than null, entry names are decoded according to
the following rules:

When the language encoding flag is not set, the specified
entryNameEncoding is used to decode the entry name.

When the language encoding flag is set, UTF-8 is used to decode the
entry name.

If I understand that section, I should be able to use something like:

        using (var archiveIn = new ZipArchive(utf8Stream, ZipArchiveMode.Read, true, Encoding.Latin1))

to be able to handle both modern UTF-8 style ZIP file, as well as handle some legacy Latin1 file that may have been written out by legacy application.

However here is what I am observing today on my system. The following xUnit test is printing:

language encoding flag is set, and entry names are encoded by using UTF-8.
language encoding flag is set, and entry names are encoded by using UTF-8.
language encoding flag is set, and entry names are encoded by using UTF-8.
ZipArchive.Latin1:
finalePräsentation.pdf
münchen.pdf
Übersicht.pdf
ZipArchive.Default:
finalePräsentation.pdf
münchen.pdf
Ãbersicht.pdf

Is there a

[Fact]
public async Task ZipArchive_Encoding()
{
    string[] entryNames = {"finalePräsentation.pdf", "münchen.pdf", "Übersicht.pdf"};
    var latin1Stream = new MemoryStream();
    var utf8Stream = new MemoryStream();
    {
        using (var archiveOut = new ZipArchive(latin1Stream, ZipArchiveMode.Create, true, Encoding.Latin1))
        {
            foreach (var entryName in entryNames)
            {
                /*
                 * When you write to archive files and entryNameEncoding is set to a value other than null,
                 * the specified entryNameEncoding is used to encode the entry names into bytes.
                 * The language encoding flag (in the general-purpose bit flag of the local file header)
                 * is set only when the specified encoding is a UTF-8 encoding.
                 */
                var entry = archiveOut.CreateEntry(entryName);
                await using var writer = new StreamWriter(entry.Open());
                await writer.WriteAsync("Hello World!");
            }
        }

        latin1Stream.Position = 0;

        using (var archiveOut = new ZipArchive(utf8Stream, ZipArchiveMode.Create, true, null))
        {
            foreach (var entryName in entryNames)
            {
                var containsOnlyAscii = entryName.All(char.IsAscii);
                if (!containsOnlyAscii)
                    output.WriteLine("language encoding flag is set, and entry names are encoded by using UTF-8.");
                else
                    output.WriteLine(
                        "the language encoding flag is not set, and entry names are encoded by using the current system default code page");
                var entry = archiveOut.CreateEntry(entryName);
                await using var writer = new StreamWriter(entry.Open());
                await writer.WriteAsync("Hello World!");
            }
        }

        utf8Stream.Position = 0;
    }
    {
        output.WriteLine("ZipArchive.Latin1:");
        using (var archiveIn = new ZipArchive(latin1Stream, ZipArchiveMode.Read, true, Encoding.Latin1))
        {
            foreach (var entry in archiveIn.Entries)
                output.WriteLine(entry.FullName);
        }

        output.WriteLine("ZipArchive.Default:");
        // When you open a zip archive file for reading and entryNameEncoding is set to a value other than null,
        using (var archiveIn = new ZipArchive(utf8Stream, ZipArchiveMode.Read, true, Encoding.Latin1))
        {
            // When the language encoding flag is set, UTF-8 is used to decode the entry name.
            foreach (var entry in archiveIn.Entries)
                output.WriteLine(entry.FullName);
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật