Class TarInputStream
The TarInputStream reads a UNIX tar archive as an InputStream. methods are provided to position at each successive entry in the archive, and the read each entry as a normal input stream using read().
Inheritance
Implements
Inherited Members
Namespace: ICSharpCode.SharpZipLib.Tar
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class TarInputStream : Stream, IDisposable
Constructors
| Improve this Doc View SourceTarInputStream(Stream)
Construct a TarInputStream with default block factor
Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public TarInputStream(Stream inputStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | stream to source data from |
TarInputStream(Stream, Int32)
Construct a TarInputStream with user specified block factor
Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public TarInputStream(Stream inputStream, int blockFactor)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | stream to source data from |
System.Int32 | blockFactor | block factor to apply to archive |
TarInputStream(Stream, Int32, Encoding)
Construct a TarInputStream with user specified block factor
Declaration
public TarInputStream(Stream inputStream, int blockFactor, Encoding nameEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | stream to source data from |
System.Int32 | blockFactor | block factor to apply to archive |
System.Text.Encoding | nameEncoding | The System.Text.Encoding used for the Name fields, or null for ASCII only |
TarInputStream(Stream, Encoding)
Construct a TarInputStream with default block factor
Declaration
public TarInputStream(Stream inputStream, Encoding nameEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | stream to source data from |
System.Text.Encoding | nameEncoding | The System.Text.Encoding used for the Name fields, or null for ASCII only |
Fields
| Improve this Doc View SourceentryFactory
Factory used to create TarEntry or descendant class instance
Declaration
protected TarInputStream.IEntryFactory entryFactory
Field Value
Type | Description |
---|---|
TarInputStream.IEntryFactory |
entryOffset
Number of bytes read for this entry so far
Declaration
protected long entryOffset
Field Value
Type | Description |
---|---|
System.Int64 |
entrySize
Size of this entry as recorded in header
Declaration
protected long entrySize
Field Value
Type | Description |
---|---|
System.Int64 |
hasHitEOF
Flag set when last block has been read
Declaration
protected bool hasHitEOF
Field Value
Type | Description |
---|---|
System.Boolean |
readBuffer
Buffer used with calls to
Read()
Declaration
protected IMemoryOwner<byte> readBuffer
Field Value
Type | Description |
---|---|
System.Buffers.IMemoryOwner<System.Byte> |
tarBuffer
Working buffer
Declaration
protected TarBuffer tarBuffer
Field Value
Type | Description |
---|---|
TarBuffer |
Properties
| Improve this Doc View SourceAvailable
Get the available data that can be read from the current entry in the archive. This does not indicate how much data is left in the entire archive, only in the current entry. This value is determined from the entry's size header field and the amount of data already read from the current entry.
Declaration
public long Available { get; }
Property Value
Type | Description |
---|---|
System.Int64 | The number of available bytes for the current entry. |
CanRead
Gets a value indicating whether the current stream supports reading
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
CanSeek
Gets a value indicating whether the current stream supports seeking This property always returns false.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
CanWrite
Gets a value indicating if the stream supports writing. This property always returns false.
Declaration
public override bool CanWrite { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsMarkSupported
Return a value of true if marking is supported; false otherwise.
Declaration
public bool IsMarkSupported { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Currently marking is not supported, the return value is always false.
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
The length in bytes of the stream
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
Position
Gets or sets the position within the stream. Setting the Position is not supported and throws a NotSupportedExceptionNotSupportedException
Declaration
public override long Position { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any attempt to set position |
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 SourceCopyEntryContents(Stream)
Copies the contents of the current tar archive entry directly into an output stream.
Declaration
public void CopyEntryContents(Stream outputStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | The OutputStream into which to write the entry's data. |
CopyEntryContentsAsync(Stream, CancellationToken)
Copies the contents of the current tar archive entry directly into an output stream.
Declaration
public Task CopyEntryContentsAsync(Stream outputStream, CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | The OutputStream into which to write the entry's data. |
System.Threading.CancellationToken | ct |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Dispose(Boolean)
Closes this stream. Calls the TarBuffer's close() method. The underlying stream is closed by the TarBuffer.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
Flush()
Flushes the baseInputStream
Declaration
public override void Flush()
Overrides
FlushAsync(CancellationToken)
Flushes the baseInputStream
Declaration
public override async Task FlushAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
GetNextEntry()
Get the next entry in this tar archive. This will skip over any remaining data in the current entry, if there is one, and place the input stream at the header of the next entry, and read the header and instantiate a new TarEntry from the header bytes and return that entry. If there are no more entries in the archive, null will be returned to indicate that the end of the archive has been reached.
Declaration
public TarEntry GetNextEntry()
Returns
Type | Description |
---|---|
TarEntry | The next TarEntry in the archive, or null. |
GetNextEntryAsync(CancellationToken)
Get the next entry in this tar archive. This will skip over any remaining data in the current entry, if there is one, and place the input stream at the header of the next entry, and read the header and instantiate a new TarEntry from the header bytes and return that entry. If there are no more entries in the archive, null will be returned to indicate that the end of the archive has been reached.
Declaration
public Task<TarEntry> GetNextEntryAsync(CancellationToken ct)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | ct |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TarEntry> | The next TarEntry in the archive, or null. |
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 | TarBuffer record size. |
Mark(Int32)
Since we do not support marking just yet, we do nothing.
Declaration
public void Mark(int markLimit)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | markLimit | The limit to mark. |
Read(Byte[], Int32, Int32)
Reads bytes from the current tar archive entry.
This method is aware of the boundaries of the current entry in the archive and will deal with them appropriately
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer into which to place bytes read. |
System.Int32 | offset | The offset at which to place bytes read. |
System.Int32 | count | The number of bytes to read. |
Returns
Type | Description |
---|---|
System.Int32 | The number of bytes read, or 0 at end of stream/EOF. |
Overrides
ReadAsync(Byte[], Int32, Int32, CancellationToken)
Reads bytes from the current tar archive entry.
This method is aware of the boundaries of the current entry in the archive and will deal with them appropriately
Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer into which to place bytes read. |
System.Int32 | offset | The offset at which to place bytes read. |
System.Int32 | count | The number of bytes to read. |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | The number of bytes read, or 0 at end of stream/EOF. |
Overrides
ReadByte()
Reads a byte from the current tar archive entry.
Declaration
public override int ReadByte()
Returns
Type | Description |
---|---|
System.Int32 | A byte cast to an int; -1 if the at the end of the stream. |
Overrides
Reset()
Since we do not support marking just yet, we do nothing.
Declaration
public void Reset()
Seek(Int64, SeekOrigin)
Set the streams position. This operation is not supported and will throw a NotSupportedException
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | offset | The offset relative to the origin to seek to. |
System.IO.SeekOrigin | origin | The System.IO.SeekOrigin to start seeking from. |
Returns
Type | Description |
---|---|
System.Int64 | The new position in the stream. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
SetEntryFactory(TarInputStream.IEntryFactory)
Set the entry factory for this instance.
Declaration
public void SetEntryFactory(TarInputStream.IEntryFactory factory)
Parameters
Type | Name | Description |
---|---|---|
TarInputStream.IEntryFactory | factory | The factory for creating new entries |
SetLength(Int64)
Sets the length of the stream This operation is not supported and will throw a NotSupportedException
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The new stream length. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
Write(Byte[], Int32, Int32)
Writes a block of bytes to this stream using data from a buffer. This operation is not supported and will throw a NotSupportedException
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | The buffer containing bytes to write. |
System.Int32 | offset | The offset in the buffer of the frist byte to write. |
System.Int32 | count | The number of bytes to write. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |
WriteByte(Byte)
Writes a byte to the current position in the file stream. This operation is not supported and will throw a NotSupportedException
Declaration
public override void WriteByte(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The byte value to write. |
Overrides
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Any access |