Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# Zip large files causes OOM exception

string[] filePaths = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "capturecapture");

using (ZipArchive zipFrom = ZipFile.Open(filePaths1[c], ZipArchiveMode.Read))
using (ZipArchive zipTo = ZipFile.Open(filePaths1[c] + ".tmp", ZipArchiveMode.Create))
{
    foreach (ZipArchiveEntry entryFrom in zipFrom.Entries)
    {
        ZipArchiveEntry entryTo = zipTo.CreateEntry(entryFrom.FullName);

        using (Stream streamFrom = entryFrom.Open())
        using (Stream streamTo = entryTo.Open())
        {
            streamFrom.CopyTo(streamTo);
        }
    }

    foreach (String filePath in filePaths)
    {
        string nm = Path.GetFileName(filePath);
        zipTo.CreateEntryFromFile(filePath, "capture/" + nm, CompressionLevel.Optimal);
    }
}

File.Delete(filePaths1[c]);
File.Move(filePaths1[c] + ".tmp", filePaths1[c]);
Comment

C# Zip large files causes OOM exception

string[] filePaths = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "capturecapture");

using (ZipArchive zipFrom = ZipFile.Open(filePaths1[c], ZipArchiveMode.Read))
using (ZipArchive zipTo = ZipFile.Open(filePaths1[c] + ".tmp", ZipArchiveMode.Create))
{
    foreach (ZipArchiveEntry entryFrom in zipFrom.Entries)
    {
        ZipArchiveEntry entryTo = zipTo.CreateEntry(entryFrom.FullName);

        using (Stream streamFrom = entryFrom.Open())
        using (Stream streamTo = entryTo.Open())
        {
            streamFrom.CopyTo(streamTo);
        }
    }

    foreach (String filePath in filePaths)
    {
        string nm = Path.GetFileName(filePath);
        zipTo.CreateEntryFromFile(filePath, "capture/" + nm, CompressionLevel.Optimal);
    }
}

File.Delete(filePaths1[c]);
File.Move(filePaths1[c] + ".tmp", filePaths1[c]);
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity move in x seconds to pos 
Csharp :: ########## 
Csharp :: for loop cs 
Csharp :: open and close autocad api 
Csharp :: difference between c# and .net 
Csharp :: How to add a dynamically created form to a new tab in Syncfusion WinForms TabControlAdv? 
Csharp :: add new page itext 7 
Csharp :: httprequestmessage with authorization .net 5 
Csharp :: Get dwgexport setting reivit api 
Csharp :: get all the file from directory except txt in c# 
Csharp :: c# 2 timespan return yesterday 
Csharp :: C# if...else Statement 
Csharp :: cmd command see which groups a user is in 
Csharp :: c# ipaddress to integer 
Csharp :: how to reset disk permission 
Csharp :: c# Detect Cycle in a Directed Graph 
Csharp :: c# check if username and password is true 
Csharp :: Wait some seconds without blocking UI execution 
Csharp :: math round to next integer c# 
Csharp :: soundplayer c# take uri 
Csharp :: does Registry.CurrentUser.OpenSubKey create the key if it does not exist? 
Csharp :: c# linq aggregate string builder 
Csharp :: radio buttons into database stackoverflow 
Csharp :: c# linq where value is max and one item 
Csharp :: LAST ELEMT OF ARRAY 
Csharp :: ASP.NET Core set update clear cache from IMemoryCache (set by Set method of CacheExtensions class) 
Csharp :: Precision comparison in C# 
Csharp :: c# psobject get value 
Csharp :: orderby make sunday last day c# 
Csharp :: wcf service dependency injection 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =