Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
extend the test to verify more, move it to outerloop as it takes a LO…
…T of time to execute it
  • Loading branch information
adamsitnik authored and github-actions committed Oct 28, 2022
commit d328131cbb8ed286f51012d9cb1f7083f20b8a84
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace System.IO.Compression.Tests
{
public class zip_LargeFiles : ZipFileTestBase
{
[Fact]
public static void ZipUnzip4GBFile()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSpeedOptimized))] // don't run it on slower runtimes
[OuterLoop("It takes more than 10 minutes")]
public static void UnzipOver4GBZipFile()
{
Random random = new (12345); // use const seed for reproducible results
byte[] buffer = new byte[1_000_000]; // 1 MB
Dictionary<string, byte[]> entiresContent = new();

string filePath = Path.Combine("ZipTestData", "large.zip");
DirectoryInfo tempDir = Directory.CreateDirectory(Path.Combine("ZipTestData", "large"));
string zipArchivePath = Path.Combine("ZipTestData", "over4GB.zip");
DirectoryInfo tempDir = Directory.CreateDirectory(Path.Combine("ZipTestData", "over4GB"));

try
{
for (int i = 0; i < 4_500; i++)
{
random.NextBytes(buffer);
File.WriteAllBytes(Path.Combine(tempDir.FullName, $"{i}.test"), buffer);

string entryName = $"{i}.test";
File.WriteAllBytes(Path.Combine(tempDir.FullName, entryName), buffer);
entiresContent.Add(entryName, buffer.ToArray());
}

ZipFile.CreateFromDirectory(tempDir.FullName, filePath);
ZipFile.CreateFromDirectory(tempDir.FullName, zipArchivePath);

using ZipArchive zipArchive = ZipFile.OpenRead(filePath);
using ZipArchive zipArchive = ZipFile.OpenRead(zipArchivePath);
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
using Stream entryStream = entry.Open();
Assert.True(entryStream.CanRead);
entryStream.ReadExactly(buffer);
Assert.Equal(entiresContent[entry.Name], buffer);
}
}
finally
{
if (File.Exists(filePath))
if (File.Exists(zipArchivePath))
{
File.Delete(filePath);
File.Delete(zipArchivePath);
}

tempDir.Delete(recursive: true);
Expand Down