久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將文件解壓縮到 .NET 內存流?

How can I unzip a file to a .NET memory stream?(如何將文件解壓縮到 .NET 內存流?)
本文介紹了如何將文件解壓縮到 .NET 內存流?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有文件(來自第 3 方)正在通過 FTP 傳輸到我們服務器上的某個目錄.我下載它們并處理它們甚至'x'分鐘.效果很好.

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.

現在,一些文件是 .zip 文件.這意味著我無法處理它們.我需要先解壓縮它們.

Now, some of the files are .zip files. Which means I can't process them. I need to unzip them first.

FTP 沒有壓縮/解壓縮的概念 - 所以我需要抓取 zip 文件,解壓縮,然后處理它.

FTP has no concept of zip/unzipping - so I'll need to grab the zip file, unzip it, then process it.

查看 MSDN zip api,我似乎無法解壓縮到內存流?

Looking at the MSDN zip api, there seems to be no way i can unzip to a memory stream?

所以這是唯一的方法......

So is the only way to do this...

  1. 解壓到一個文件(什么目錄?需要一些非常臨時的位置...)
  2. 讀取文件內容
  3. 刪除文件.

注意:文件的內容很小 - 比如 4k <-> 1000k.

NOTE: The contents of the file are small - say 4k <-> 1000k.

推薦答案

Zip壓縮支持內置:

using System.IO;
using System.IO.Compression;
// ^^^ requires a reference to System.IO.Compression.dll
static class Program
{
    const string path = ...
    static void Main()
    {
        using(var file = File.OpenRead(path))
        using(var zip = new ZipArchive(file, ZipArchiveMode.Read))
        {
            foreach(var entry in zip.Entries)
            {
                using(var stream = entry.Open())
                {
                    // do whatever we want with stream
                    // ...
                }
            }
        }
    }
}

通常您應該避免將其復制到另一個流中 - 只需按原樣"使用它,但是,如果您在 MemoryStream絕對需要它,您可以這樣做:

Normally you should avoid copying it into another stream - just use it "as is", however, if you absolutely need it in a MemoryStream, you could do:

using(var ms = new MemoryStream())
{
    stream.CopyTo(ms);
    ms.Position = 0; // rewind
    // do something with ms
}

這篇關于如何將文件解壓縮到 .NET 內存流?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 伊人网在线视频 | 成年女人毛片 | 亚洲精品乱码久久久久久蜜桃91 | 黄色激情网站 | 亚洲国产成人精品女人久久久 | 免费黄色av | 久久免费国产 | 黄色小视频在线观看免费 | 中文字幕av在线 | 午夜在线视频观看日韩17c | 黄色免费在线视频 | 久久精彩| 欧美日韩a| 久久久精品网 | 久久久黄色片 | 激情五月激情综合网 | 国产日韩精品一区二区 | 成人免费看 | www久| av福利在线| 亚洲视频网 | 国产激情视频在线观看 | 日韩一区二区三 | 长河落日| 91精品成人| 东方成人av | 日韩在线免费 | 毛片毛片毛片 | 精品一区二区三区在线观看 | 91看片在线观看 | 亚洲狠狠爱 | 在线观看av网站 | 亚洲伦理精品 | 99久久视频 | 91看片看淫黄大片 | 国产手机在线视频 | 久在线观看 | 欧美啪啪网 | 日韩一区精品 | 国产一级片免费看 | 日韩精品免费在线观看 |