久久久久久久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 超時)
主站蜘蛛池模板: 国产在线视频在线观看 | 在线观看特色大片免费网站 | 亚洲天天干 | 少妇无套高潮一二三区 | 99精品免费| 91精品国产乱码久久久久久久 | 成人国产在线视频 | 欧美一区二区在线 | 毛片一区二区三区 | 亚洲成人免费在线观看 | 欧美一区二区三区在线观看 | 色精品视频 | 伊人狠狠干 | 黄色片在线观看网址 | 一区二区三区高清 | 日韩精品免费在线 | 一区二区三区国产好的精 | 一区二区三区国产视频 | 国产精品视频一区二区三区不卡 | 在线观看成人免费视频 | 久久高清精品 | 亚洲欧美成人 | 在线观看av不卡 | 中文av在线播放 | 国产一区在线免费观看 | 成人在线免费观看 | 99久久久久久久 | 在线a视频网站 | 精久久久久 | 蜜桃av人人夜夜澡人人爽 | 久久久精品一区二区三区 | 国产精品视频久久久 | 午夜精品久久久久久久久久久久 | 人人射人人草 | 午夜看片网站 | 日韩美女爱爱 | 天天亚洲 | 日本久久综合 | 精品粉嫩超白一线天av | 亚洲一区二区三区视频 | 久久99精品视频 |