Compression
Overview
VersaTul.Compression provides a small abstraction over System.IO.Compression for zipping and unzipping in-memory files.
The package centers around ZipStream objects, which pair a file name, content type, and MemoryStream so higher-level workflows can archive generated files without dealing directly with zip entry wiring.
When To Use This Package
Use this package when you want to:
Package one or many in-memory files into a zip archive.
Extract zip archives back into named in-memory streams.
Keep compression concerns separate from file generation logic.
Support workflows that generate exports before saving, emailing, or uploading them.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Compression
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Compression -Version latest
Core Types And Concepts
ZipStreamCarries the file name, content type, and in-memory content to archive.
IArchiverandArchiverWrite individual
ZipStreaminstances into aZipArchive.IZipperandZipperCreate zip archives from one or many
ZipStreamobjects and can also unzip archive streams.
Key Capabilities
Zip a single
ZipStreamor a collection of them.Choose a specific
CompressionLevelwhen creating the archive.Unzip archive streams back into
ZipStreaminstances.Filter extracted entries during unzip with a predicate.
Basic Example
using System.IO;
using VersaTul.Compression;
IArchiver archiver = new Archiver();
IZipper zipper = new Zipper(archiver);
var zipStream = new ZipStream
{
ContentType = "text/csv",
FileName = "people.csv",
Stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("Name,Age\nJane,42"))
};
using var archive = zipper.Zip(zipStream);
Unzip Example
using var archiveStream = File.OpenRead("exports.zip");
var files = zipper.Unzip(archiveStream, entryName => entryName.EndsWith(".csv"));
foreach (var item in files)
{
Console.WriteLine(item.FileName);
}
Notes
ZipStream.Streamis aMemoryStream, so this package is best suited to in-memory export workflows.The package does not decide where archives are stored or sent; pair it with Handler File or Collection Streamers depending on your workflow.