How can I unzip a file to a .NET memory stream?

前端 未结 6 604
鱼传尺愫
鱼传尺愫 2020-12-14 00:16

I have files (from 3rd parties) that are being FTP\'d to a directory on our server. I download them and process them even \'x\' minutes. Works great.

Now, some of th

6条回答
  •  庸人自扰
    2020-12-14 00:48

    You can use ZipArchiveEntry.Open to get a stream.

    This code assumes the zip archive has one text file.

    using (FileStream fs = new FileStream(path, FileMode.Open))
    using (ZipArchive zip = new ZipArchive(fs) )
    {
        var entry = zip.Entries.First();
    
        using (StreamReader sr = new StreamReader(entry.Open()))
        {
            Console.WriteLine(sr.ReadToEnd());
        }
    }
    

提交回复
热议问题