Skip to content

Zip ​

Zip is designed for multi-file archives and directory packaging.

It supports:

  • Single-entry compression
  • Multi-file in-memory archives
  • File-based archive creation
  • Safe directory extraction
  • Zip bomb detection

Methods ​

Compress a Single Entry ​

csharp
using JASE.Compression;

byte[] archive = Zip.Compress(data, entryName: "file.txt");
byte[] original = Zip.Decompress(archive, "file.txt");

Create Archive in Memory ​

csharp
using JASE.Compression;

var entries = new List<ZipFileEntry>
{
    new ZipFileEntry { FileName = "a.txt", Content = aBytes },
    new ZipFileEntry { FileName = "b.txt", Content = bBytes }
};

byte[] archive = Zip.CreateZipFileInMemory(entries);

Extract Safely ​

csharp
using JASE.Compression;

Zip.ExtractToDirectory("archive.zip", "output-folder");

Extraction protection includes:

  • Path traversal prevention (../ defense)
  • Rooted path rejection
  • Drive-letter rejection
  • Zip bomb detection
  • Maximum path depth enforcement
  • Compression ratio limits
  • Total uncompressed size limits

Zip Bomb Detection ​

csharp
using JASE.Compression;

bool isBomb = Zip.IsZipBomb("archive.zip");

Overloads exist for:

  • string filename
  • byte[]
  • Stream

ZipBombOptions allows tuning thresholds such as:

  • Max entry count
  • Max path depth
  • Max single entry size
  • Max total uncompressed size
  • Max compression ratio