[Root] / Xceed Data Manipulation Components for .NET / [Root] / Basic Concepts / [Root] / Tar and GZip capabilities / [Root] / Xceed Tar / Listing the contents of a tar archive

In This Topic
    Listing the contents of a tar archive
    In This Topic

    This topic demonstrates how to get a listing of all of the files contained in a GZipped Tar archive, that is, a Tar archive that has been compressed using GZip. Note: Tar and FileSystem-based GZip are not currently available in Xceed's .NET Compact Framework products.

    Basic steps

    To list the contents of a gzipped Tar archive, the following steps must be performed:

    When performing many operations on an archive, you may wish to consider optimizing your code by using batch updates.

    Using a non-GZipped Tar archive may be preferable in some situations: for example, when read/write speed is essential but storage space is unlimited, when you need to access individual files in the Tar archive without uncompressing the entire archive, or when the files inside the Tar archive are already compressed.

    Setting the LicenseKey property with Tar also unlocks the GZip capabilities.

    Demonstration

    This example demonstrates how to list the contents of a GZipped Tar archive.

    VB.NET Copy Code

    Imports Xceed.Tar
    Imports Xceed.GZip
    Imports Xceed.FileSystem

    Dim diskFile As New DiskFile("c:\test.tar.gz")
    Dim gzip As New GZippedFile(diskFile)
    Dim tar As New TarArchive(gzip)

    Dim f As AbstractFile 

    For Each f In tar.GetFiles( True )
       ListBox1.Items.Add( f.FullName )
    Next

    C# Copy Code

    using Xceed.Tar;
    using Xceed.GZip;
    using Xceed.FileSystem; 

    DiskFile diskFile = new DiskFile(@"E:\test.tar.gz");
    GZippedFile gzip = new GZippedFile(diskFile);
    TarArchive tar = new TarArchive(gzip);

    foreach (AbstractFile file in tar.GetFiles(true))
    {
      Console.WriteLine("File {0} is {1} bytes", file.FullName, file.Size);
    }

    Things you should consider

    The main questions you should ask yourself when listing the contents of a Tar file are: