C# Class ICSharpCode.SharpZipLib.Tar.TarArchive

The TarArchive class implements the concept of a 'Tape Archive'. A tar archive is a series of entries, each of which represents a file system object. Each entry in the archive consists of a header block followed by 0 or more data blocks. Directory entries consist only of the header block, and are followed by entries for the directory's contents. File entries consist of a header followed by the number of blocks needed to contain the file's contents. All entries are written on block boundaries. Blocks are 512 bytes long. TarArchives are instantiated in either read or write mode, based upon whether they are instantiated with an InputStream or an OutputStream. Once instantiated TarArchives read/write mode can not be changed. There is currently no support for random access to tar archives. However, it seems that subclassing TarArchive, and using the TarBuffer.CurrentRecord and TarBuffer.CurrentBlock properties, this would be rather trivial.
Inheritance: IDisposable
Show file Open project: icsharpcode/SharpZipLib Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Closes the archive and releases any associated resources.

CreateInputTarArchive ( Stream inputStream ) : TarArchive

The InputStream based constructors create a TarArchive for the purposes of extracting or listing a tar archive. Thus, use these constructors when you wish to extract files from or list the contents of an existing tar archive.

CreateInputTarArchive ( Stream inputStream, int blockFactor ) : TarArchive

Create TarArchive for reading setting block factor

CreateOutputTarArchive ( Stream outputStream ) : TarArchive

Create a TarArchive for writing to, using the default blocking factor

CreateOutputTarArchive ( Stream outputStream, int blockFactor ) : TarArchive

Create a tar archive for writing.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

ExtractContents ( string destinationDirectory ) : void

Perform the "extract" command and extract the contents of the archive.

ListContents ( ) : void

Perform the "list" command for the archive contents. NOTE That this method uses the progress event to actually list the contents. If the progress display event is not set, nothing will be listed!

SetKeepOldFiles ( bool keepExistingFiles ) : void

Set the flag that determines whether existing files are kept, or overwritten during extraction.

SetUserInfo ( int userId, string userName, int groupId, string groupName ) : void

Set user and group information that will be used to fill in the tar archive's entry headers. This information is based on that available for the linux operating system, which is not always available on other operating systems. TarArchive allows the programmer to specify values to be used in their place. ApplyUserInfoOverrides is set to true by this call.

WriteEntry ( TarEntry sourceEntry, bool recurse ) : void

Write an entry to the archive. This method will call the putNextEntry and then write the contents of the entry, and finally call closeEntry() for entries that are files. For directories, it will call putNextEntry(), and then, if the recurse flag is true, process each entry that is a child of the directory.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the FileStream and optionally releases the managed resources.

OnProgressMessageEvent ( TarEntry entry, string message ) : void

Raises the ProgressMessage event

TarArchive ( ) : System

Constructor for a default TarArchive.

TarArchive ( TarInputStream stream ) : System

Initalise a TarArchive for input.

TarArchive ( TarOutputStream stream ) : System

Initialise a TarArchive for output.

Private Methods

Method Description
CloseArchive ( ) : void
EnsureDirectoryExists ( string directoryName ) : void
ExtractEntry ( string destDir, TarEntry entry ) : void

Extract an entry from the archive. This method assumes that the tarIn stream has been properly set with a call to GetNextEntry().

IsBinary ( string filename ) : bool
SetAsciiTranslation ( bool translateAsciiFiles ) : void
WriteEntryCore ( TarEntry sourceEntry, bool recurse ) : void

Write an entry to the archive. This method will call the putNextEntry and then write the contents of the entry, and finally call closeEntry() for entries that are files. For directories, it will call putNextEntry(), and then, if the recurse flag is true, process each entry that is a child of the directory.

Method Details

Close() public method

Closes the archive and releases any associated resources.
public Close ( ) : void
return void

CreateInputTarArchive() public static method

The InputStream based constructors create a TarArchive for the purposes of extracting or listing a tar archive. Thus, use these constructors when you wish to extract files from or list the contents of an existing tar archive.
public static CreateInputTarArchive ( Stream inputStream ) : TarArchive
inputStream Stream The stream to retrieve archive data from.
return TarArchive

CreateInputTarArchive() public static method

Create TarArchive for reading setting block factor
public static CreateInputTarArchive ( Stream inputStream, int blockFactor ) : TarArchive
inputStream Stream A stream containing the tar archive contents
blockFactor int The blocking factor to apply
return TarArchive

CreateOutputTarArchive() public static method

Create a TarArchive for writing to, using the default blocking factor
public static CreateOutputTarArchive ( Stream outputStream ) : TarArchive
outputStream Stream The to write to
return TarArchive

CreateOutputTarArchive() public static method

Create a tar archive for writing.
public static CreateOutputTarArchive ( Stream outputStream, int blockFactor ) : TarArchive
outputStream Stream The stream to write to
blockFactor int The blocking factor to use for buffering.
return TarArchive

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by the FileStream and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; /// false to release only unmanaged resources.
return void

ExtractContents() public method

Perform the "extract" command and extract the contents of the archive.
public ExtractContents ( string destinationDirectory ) : void
destinationDirectory string /// The destination directory into which to extract. ///
return void

ListContents() public method

Perform the "list" command for the archive contents. NOTE That this method uses the progress event to actually list the contents. If the progress display event is not set, nothing will be listed!
public ListContents ( ) : void
return void

OnProgressMessageEvent() protected method

Raises the ProgressMessage event
protected OnProgressMessageEvent ( TarEntry entry, string message ) : void
entry TarEntry The TarEntry for this event
message string message for this event. Null is no message
return void

SetKeepOldFiles() public method

Set the flag that determines whether existing files are kept, or overwritten during extraction.
public SetKeepOldFiles ( bool keepExistingFiles ) : void
keepExistingFiles bool /// If true, do not overwrite existing files. ///
return void

SetUserInfo() public method

Set user and group information that will be used to fill in the tar archive's entry headers. This information is based on that available for the linux operating system, which is not always available on other operating systems. TarArchive allows the programmer to specify values to be used in their place. ApplyUserInfoOverrides is set to true by this call.
public SetUserInfo ( int userId, string userName, int groupId, string groupName ) : void
userId int /// The user id to use in the headers. ///
userName string /// The user name to use in the headers. ///
groupId int /// The group id to use in the headers. ///
groupName string /// The group name to use in the headers. ///
return void

TarArchive() protected method

Constructor for a default TarArchive.
protected TarArchive ( ) : System
return System

TarArchive() protected method

Initalise a TarArchive for input.
protected TarArchive ( TarInputStream stream ) : System
stream TarInputStream The to use for input.
return System

TarArchive() protected method

Initialise a TarArchive for output.
protected TarArchive ( TarOutputStream stream ) : System
stream TarOutputStream The to use for output.
return System

WriteEntry() public method

Write an entry to the archive. This method will call the putNextEntry and then write the contents of the entry, and finally call closeEntry() for entries that are files. For directories, it will call putNextEntry(), and then, if the recurse flag is true, process each entry that is a child of the directory.
public WriteEntry ( TarEntry sourceEntry, bool recurse ) : void
sourceEntry TarEntry /// The TarEntry representing the entry to write to the archive. ///
recurse bool /// If true, process the children of directory entries. ///
return void