Class 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
Implements
Inherited Members
Namespace: ICSharpCode.SharpZipLib.Tar
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class TarOutputStream : Stream, IDisposable
Constructors
| Improve this Doc View SourceTarOutputStream(Stream)
Construct TarOutputStream using default block factor
Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public TarOutputStream(Stream outputStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | stream to write to |
TarOutputStream(Stream, Int32)
Construct TarOutputStream with user specified block factor
Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public TarOutputStream(Stream outputStream, int blockFactor)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | stream to write to |
System.Int32 | blockFactor | blocking factor |
TarOutputStream(Stream, Int32, Encoding)
Construct TarOutputStream with user specified block factor
Declaration
public TarOutputStream(Stream outputStream, int blockFactor, Encoding nameEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | stream to write to |
System.Int32 | blockFactor | blocking factor |
System.Text.Encoding | nameEncoding | The System.Text.Encoding used for the Name fields, or null for ASCII only |
TarOutputStream(Stream, Encoding)
Construct TarOutputStream using default block factor
Declaration
public TarOutputStream(Stream outputStream, Encoding nameEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | stream to write to |
System.Text.Encoding | nameEncoding | The System.Text.Encoding used for the Name fields, or null for ASCII only |
Fields
| Improve this Doc View SourceassemblyBuffer
'Assembly' buffer used to assemble data before writing
Declaration
protected byte[] assemblyBuffer
Field Value
Type | Description |
---|---|
System.Byte[] |
blockBuffer
single block working buffer
Declaration
protected byte[] blockBuffer
Field Value
Type | Description |
---|---|
System.Byte[] |
buffer
TarBuffer used to provide correct blocking factor
Declaration
protected TarBuffer buffer
Field Value
Type | Description |
---|---|
TarBuffer |
currSize
Size for the current entry
Declaration
protected long currSize
Field Value
Type | Description |
---|---|
System.Int64 |
nameEncoding
name encoding
Declaration
protected Encoding nameEncoding
Field Value
Type | Description |
---|---|
System.Text.Encoding |
outputStream
the destination stream for the archive contents
Declaration
protected Stream outputStream
Field Value
Type | Description |
---|---|
System.IO.Stream |
Properties
| Improve this Doc View SourceCanRead
true if the stream supports reading; otherwise, false.
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
CanSeek
true if the stream supports seeking; otherwise, false.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
CanWrite
true if stream supports writing; otherwise, false.
Declaration
public override bool CanWrite { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsStreamOwner
Gets or sets a flag indicating ownership of underlying stream. When the flag is true System.IO.Stream.Dispose() will close the underlying stream also.
Declaration
public bool IsStreamOwner { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
The default value is true.
Length
length of stream in bytes
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
Position
gets or sets the position within the current stream.
Declaration
public override long Position { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
RecordSize
Get the record size being used by this stream's TarBuffer.
Declaration
public int RecordSize { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceCloseEntry()
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.
Declaration
public void CloseEntry()
CloseEntryAsync(CancellationToken)
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.
Declaration
public Task CloseEntryAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Dispose(Boolean)
Ends the TAR archive and closes the underlying OutputStream.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
Remarks
This means that Finish() is called followed by calling the TarBuffer's Close().
Finish()
Ends the TAR archive without closing the underlying OutputStream. The result is that the EOF block of nulls is written.
Declaration
public void Finish()
FinishAsync(CancellationToken)
Ends the TAR archive without closing the underlying OutputStream. The result is that the EOF block of nulls is written.
Declaration
public Task FinishAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Flush()
All buffered data is written to destination
Declaration
public override void Flush()
Overrides
FlushAsync(CancellationToken)
All buffered data is written to destination
Declaration
public override async Task FlushAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
GetRecordSize()
Get the record size being used by this stream's TarBuffer.
Declaration
[Obsolete("Use RecordSize property instead")]
public int GetRecordSize()
Returns
Type | Description |
---|---|
System.Int32 | The TarBuffer record size. |
PutNextEntry(TarEntry)
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.
Declaration
public void PutNextEntry(TarEntry entry)
Parameters
Type | Name | Description |
---|---|---|
TarEntry | entry | The TarEntry to be written to the archive. |
PutNextEntryAsync(TarEntry, CancellationToken)
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.
Declaration
public Task PutNextEntryAsync(TarEntry entry, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
TarEntry | entry | The TarEntry to be written to the archive. |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Read(Byte[], Int32, Int32)
read bytes from the current stream and advance the position within the stream by the number of bytes read.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to store read bytes in. |
System.Int32 | offset | The index into the buffer to being storing bytes at. |
System.Int32 | count | The desired number of bytes to read. |
Returns
Type | Description |
---|---|
System.Int32 | The total number of bytes read, or zero if at the end of the stream.
The number of bytes may be less than the |
Overrides
ReadAsync(Byte[], Int32, Int32, CancellationToken)
read bytes from the current stream and advance the position within the stream by the number of bytes read.
Declaration
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to store read bytes in. |
System.Int32 | offset | The index into the buffer to being storing bytes at. |
System.Int32 | count | The desired number of bytes to read. |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | The total number of bytes read, or zero if at the end of the stream.
The number of bytes may be less than the |
Overrides
ReadByte()
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.
Declaration
public override int ReadByte()
Returns
Type | Description |
---|---|
System.Int32 | The byte value or -1 if at end of stream |
Overrides
Seek(Int64, SeekOrigin)
set the position within the current stream
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | offset | The offset relative to the |
System.IO.SeekOrigin | origin | The System.IO.SeekOrigin to seek from. |
Returns
Type | Description |
---|---|
System.Int64 | The new position in the stream. |
Overrides
SetLength(Int64)
Set the length of the current stream
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The new stream length. |
Overrides
Write(Byte[], Int32, Int32)
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.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to write to the archive. |
System.Int32 | offset | The offset in the buffer from which to get bytes. |
System.Int32 | count | The number of bytes to write. |
Overrides
WriteAsync(Byte[], Int32, Int32, CancellationToken)
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.
Declaration
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer to write to the archive. |
System.Int32 | offset | The offset in the buffer from which to get bytes. |
System.Int32 | count | The number of bytes to write. |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
WriteByte(Byte)
Writes a byte to the current tar archive entry. This method simply calls Write(byte[], int, int).
Declaration
public override void WriteByte(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The byte to be written. |