ZipArchive不会修改内存流

时间:2018-03-06 15:32:46

标签: c# webrequest memorystream

我尝试下载zip文件并在返回之前对其进行修改。我希望在更新模式下使用ZipArchive添加其他文件后修改流。但是,它保持不变。我究竟做错了什么?

using (WebClient webClient = new WebClient())
{
    string url = "http://www.dynaexamples.com/examples-manual/ls-dyna_example.zip/at_download/file";
    byte[] downloadedData = webClient.DownloadData(url);

    using (MemoryStream stream = new MemoryStream())
    {
        stream.Write(downloadedData, 0, downloadedData.Length);
        Console.WriteLine(stream.Length.ToString()); //911616

        ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Update);
        ZipArchiveEntry testFile = archive.CreateEntry("test.txt");
        using (StreamWriter writer = new StreamWriter(testFile.Open()))
        {
            writer.WriteLine("test");
            writer.Flush();
        }
        Console.WriteLine(stream.Length.ToString()); //911616
    }
}

0 个答案:

没有答案