Xceed Zip for .NET contains FileSystem (derived from AbstractFile/AbstractFolder) clases for Tar. However, it only contains FileSystem classes for GZip and not BZip2.
However, our streaming compression component, Xceed.Compression.Formats, contains a BZip2 compressed stream class. Using that, Tar/BZip2 (.Tbz) archives can be created.
staticvoid Example()
{
Xceed.Tar.Licenser.LicenseKey = "<your ZIN license key>";
Xceed.Compression.Formats.Licenser.LicenseKey = "<your ZIN license key>";
AbstractFile tbzFile;
// Select the Tar-BZip2 file
tbzFile = new DiskFile( "Example.tbz" );
// If the Tar-BZip2 file already exists
if( tbzFile.Exists )
// Delete it. We want to create a new archive, not update an existing one
tbzFile.Delete();
// Create and open the Tar-BZip2 file
using( Stream stream = tbzFile.CreateWrite() )
{
// Wrap the file stream with a BZip2 stream
using( BZip2CompressedStream bzip2Stream = new BZip2CompressedStream( stream ) )
{
// Wrap the BZip2 stream with a StreamFile object so we can feed it to FileSystem calls
StreamFile streamFile = new StreamFile( bzip2Stream );
// Create a logical Tar archive around the BZip2 stream file
TarArchive tar = new TarArchive( streamFile );
// Select a source folder
AbstractFolder sourceFolder = new DiskFolder( @"D:\Data" );
using( AutoBatchUpdate batch = new AutoBatchUpdate( tar ) )
{
// Add the files from the source folder to the archive
sourceFolder.CopyFilesTo( tar, true, true );
}
}
}
}
PrivateSharedSub Example()
Xceed.Tar.Licenser.LicenseKey = "<your ZIN license key>"
Xceed.Compression.Formats.Licenser.LicenseKey = "<your ZIN license key>"Dim tbzFile As AbstractFile
' Select the Tar-BZip2 file
tbzFile = New DiskFile("Example.tbz")
' If the Tar-BZip2 file already exists
If tbzFile.Exists Then' Delete it. We want to create a new archive, not update an existing one
tbzFile.Delete()
EndIf' Create and open the Tar-BZip2 file
Using stream As Stream = tbzFile.CreateWrite()
' Wrap the file stream with a BZip2 stream
Using bzip2Stream AsNew BZip2CompressedStream(stream)
' Wrap the BZip2 stream with a StreamFile object so we can feed it to FileSystem calls
Dim streamFile AsNew StreamFile(bzip2Stream)
' Create a logical Tar archive around the BZip2 stream file
Dim tar AsNew TarArchive(streamFile)
' Select a source folder
Dim sourceFolder As AbstractFolder = New DiskFolder("D:\Data")
Using batch AsNew AutoBatchUpdate(tar)
' Add the files from the source folder to the archive
sourceFolder.CopyFilesTo(tar, True, True)
EndUsingEndUsingEndUsingEnd Sub