Skip to content
Andrew Lambert edited this page Nov 26, 2022 · 12 revisions

USTAR.TarReader

Class Declaration

 Protected Class TarReader

Remarks

Note: For basic archive reading/writing see the ReadTar and WriteTar utility methods.

This class reads a tape archive. To create a new instance pass a Readable object containing the archive to the Constructor method. The archive is processed one entry at a time, from the first entry to the last.

Create a new instance, and access the "Current*" properties to read metadata of the current item in the archive.

Call the MoveNext method to process the current item and then advance the selection to the next item in the archive. MoveNext will return True until an error occurs; note that this includes reaching the end of the archive, so check LastError for details.

Example

This example scans through the archive until it finds a file with a specific name and then it extracts only that file:

  Dim tarfile As FolderItem = GetOpenFolderItem("") ' the tape archive to read
  Dim ts As BinaryStream = BinaryStream.Open(tarfile) ' can also be a zlib.ZStream for gzipped archives
  Dim tar As New USTAR.TarReader(ts)
  Dim outputfile As FolderItem = SpecialFolder.Desktop.Child("file.txt")
  Dim output As BinaryStream = BinaryStream.Create(outputfile)
  Do 
    If tar.CurrentName = "path/to/the/file.txt" Then
      ' we found the file. Extract it into the output stream
      Call tar.MoveNext(output)
      Exit Do ' done
    End If
  Loop Until Not tar.MoveNext(Nil) ' skip extraction and load the next entry
  output.Close
  tar.Close

Methods

Properties

Entry-level points of interest denoted by "☜"



Clone this wiki locally