從 Zip 檔案中獲取檔案

此示例從提供的 zip 存檔二進位制資料中獲取檔案列表:

public static Dictionary<string, byte[]> GetFiles(byte[] zippedFile) 
{
    using (MemoryStream ms = new MemoryStream(zippedFile))
    using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read)) 
    {
        return archive.Entries.ToDictionary(x => x.FullName, x => ReadStream(x.Open()));
    }
}

private static byte[] ReadStream(Stream stream) 
{
    using (var ms = new MemoryStream()) 
    {
        stream.CopyTo(ms);
        return ms.ToArray();
    }
}