Working with Z Archives

Overview

Aspose.ZIP for .NET API lets you create and manage Z archives in your applications without the need for additional third-party tools. The API provides the  ZArchive class, which offers basic methods to perform archive operations.

The Unix compress utility produces archives with the .Z extension and implements the LZC algorithm, a modification of the LZW algorithm.

Compress a File

The following code example demonstrates how to compress a file using a ZArchive instance:

1    using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
2    {
3        using (ZArchive archive = new ZArchive())
4        {
5            archive.SetSource(source);
6            archive.Save("alice29.txt.Z");
7        }
8    }

Open Z Archive

The following code example illustrates how to open a Z archive:

1    FileInfo fi = new FileInfo("data.bin.Z");
2
3    using (ZArchive archive = new ZArchive(fi.OpenRead()))
4    {
5        archive.Extract("data.bin");
6    }

Save to Stream

The following code example shows how to save an archive to a stream:

1    MemoryStream ms = new MemoryStream();
2    using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
3    {
4        using (ZArchive archive = new ZArchive())
5        {
6            archive.SetSource(source);
7            archive.Save(ms);
8        }
9    }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.