C# Class ICSharpCode.SharpZipLib.Tar.TarOutputStream

The TarOutputStream writes a UNIX tar archive as an OutputStream. Methods are provided to put entries, and then write their contents by writing to this stream using write().
Inheritance: Stream
Show file Open project: icsharpcode/SharpZipLib Class Usage Examples

Protected Properties

Property Type Description
assemblyBuffer byte[]
blockBuffer byte[]
buffer TarBuffer
currSize long
outputStream Stream

Private Properties

Property Type Description
GetRecordSize int

Public Methods

Method Description
CloseEntry ( ) : void

Close an entry. This method MUST be called for all file entries that contain data. The reason is that we must buffer data written to the stream in order to satisfy the buffer's block based writes. Thus, there may be data fragments still being assembled that must be written to the output stream before this entry is closed and the next entry written.

Finish ( ) : void

Ends the TAR archive without closing the underlying OutputStream. The result is that the EOF block of nulls is written.

Flush ( ) : void

All buffered data is written to destination

PutNextEntry ( TarEntry entry ) : void

Put an entry on the output stream. This writes the entry's header and positions the output stream for writing the contents of the entry. Once this method is called, the stream is ready for calls to write() to write the entry's contents. Once the contents are written, closeEntry() MUST be called to ensure that all buffered data is completely written to the output stream.

Read ( byte buffer, int offset, int count ) : int

read bytes from the current stream and advance the position within the stream by the number of bytes read.

ReadByte ( ) : int

Read a byte from the stream and advance the position within the stream by one byte or returns -1 if at the end of the stream.

Seek ( long offset, SeekOrigin origin ) : long

set the position within the current stream

SetLength ( long value ) : void

Set the length of the current stream

TarOutputStream ( Stream outputStream ) : System

Construct TarOutputStream using default block factor

TarOutputStream ( Stream outputStream, int blockFactor ) : System

Construct TarOutputStream with user specified block factor

Write ( byte buffer, int offset, int count ) : void

Writes bytes to the current tar archive entry. This method is aware of the current entry and will throw an exception if you attempt to write bytes past the length specified for the current entry. The method is also (painfully) aware of the record buffering required by TarBuffer, and manages buffers that are not a multiple of recordsize in length, including assembling records from small buffers.

WriteByte ( byte value ) : void

Writes a byte to the current tar archive entry. This method simply calls Write(byte[], int, int).

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Ends the TAR archive and closes the underlying OutputStream.

This means that Finish() is called followed by calling the TarBuffer's Close().

WriteEofBlock ( ) : void

Write an EOF (end of archive) block to the tar archive. An EOF block consists of all zeros.

Private Methods

Method Description
GetRecordSize ( ) : int

Method Details

CloseEntry() public method

Close an entry. This method MUST be called for all file entries that contain data. The reason is that we must buffer data written to the stream in order to satisfy the buffer's block based writes. Thus, there may be data fragments still being assembled that must be written to the output stream before this entry is closed and the next entry written.
public CloseEntry ( ) : void
return void

Dispose() protected method

Ends the TAR archive and closes the underlying OutputStream.
This means that Finish() is called followed by calling the TarBuffer's Close().
protected Dispose ( bool disposing ) : void
disposing bool
return void

Finish() public method

Ends the TAR archive without closing the underlying OutputStream. The result is that the EOF block of nulls is written.
public Finish ( ) : void
return void

Flush() public method

All buffered data is written to destination
public Flush ( ) : void
return void

PutNextEntry() public method

Put an entry on the output stream. This writes the entry's header and positions the output stream for writing the contents of the entry. Once this method is called, the stream is ready for calls to write() to write the entry's contents. Once the contents are written, closeEntry() MUST be called to ensure that all buffered data is completely written to the output stream.
public PutNextEntry ( TarEntry entry ) : void
entry TarEntry /// The TarEntry to be written to the archive. ///
return void

Read() public method

read bytes from the current stream and advance the position within the stream by the number of bytes read.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer to store read bytes in.
offset int The index into the buffer to being storing bytes at.
count int The desired number of bytes to read.
return int

ReadByte() public method

Read a byte from the stream and advance the position within the stream by one byte or returns -1 if at the end of the stream.
public ReadByte ( ) : int
return int

Seek() public method

set the position within the current stream
public Seek ( long offset, SeekOrigin origin ) : long
offset long The offset relative to the to seek to
origin SeekOrigin The to seek from.
return long

SetLength() public method

Set the length of the current stream
public SetLength ( long value ) : void
value long The new stream length.
return void

TarOutputStream() public method

Construct TarOutputStream using default block factor
public TarOutputStream ( Stream outputStream ) : System
outputStream Stream stream to write to
return System

TarOutputStream() public method

Construct TarOutputStream with user specified block factor
public TarOutputStream ( Stream outputStream, int blockFactor ) : System
outputStream Stream stream to write to
blockFactor int blocking factor
return System

Write() public method

Writes bytes to the current tar archive entry. This method is aware of the current entry and will throw an exception if you attempt to write bytes past the length specified for the current entry. The method is also (painfully) aware of the record buffering required by TarBuffer, and manages buffers that are not a multiple of recordsize in length, including assembling records from small buffers.
public Write ( byte buffer, int offset, int count ) : void
buffer byte /// The buffer to write to the archive. ///
offset int /// The offset in the buffer from which to get bytes. ///
count int /// The number of bytes to write. ///
return void

WriteByte() public method

Writes a byte to the current tar archive entry. This method simply calls Write(byte[], int, int).
public WriteByte ( byte value ) : void
value byte /// The byte to be written. ///
return void

WriteEofBlock() protected method

Write an EOF (end of archive) block to the tar archive. An EOF block consists of all zeros.
protected WriteEofBlock ( ) : void
return void

Property Details

assemblyBuffer protected property

'Assembly' buffer used to assemble data before writing
protected byte[] assemblyBuffer
return byte[]

blockBuffer protected property

single block working buffer
protected byte[] blockBuffer
return byte[]

buffer protected property

TarBuffer used to provide correct blocking factor
protected TarBuffer,ICSharpCode.SharpZipLib.Tar buffer
return TarBuffer

currSize protected property

Size for the current entry
protected long currSize
return long

outputStream protected property

the destination stream for the archive contents
protected Stream outputStream
return Stream