久久久久久久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 超時)
主站蜘蛛池模板: 国产 欧美 日韩 一区 | 亚洲va中文字幕 | 国产日产久久高清欧美一区 | 隔壁老王国产在线精品 | 精品国产色 | 91久久精品一区二区二区 | 欧美精品欧美精品系列 | 日韩视频一区二区三区 | 日日骚av | 伊人超碰 | 国产视频一区二区 | 一区二区视频在线 | 欧美v日韩| 亚洲精品电影网在线观看 | 国产精品久久久久久久一区探花 | 日本精品一区二区 | 女人牲交视频一级毛片 | 中文字幕一页二页 | 欧美在线观看一区 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 久久99深爱久久99精品 | 中文字幕一区二区三区四区五区 | 青青久草 | 中国人pornoxxx麻豆 | 中文字幕一区二区三区精彩视频 | 日日夜夜视频 | 久久久久国产一区二区 | 九九视频在线观看视频6 | 中文字幕在线看人 | 99精品久久 | 青娱乐自拍 | 日韩精品在线观看网站 | 中文字幕一区二区三区在线观看 | 9999视频| 国产一区二区a | 一呦二呦三呦国产精品 | 国产一区二区影院 | 久久久久久久久久久久久9999 | 日韩精品福利 | 欧美国产日韩一区 | 91成人免费观看 |