Show / Hide Table of Contents

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
System.Object
System.MarshalByRefObject
System.IO.Stream
TarInputStream
Implements
System.IDisposable
Inherited Members
System.IO.Stream.Null
System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.Close()
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.Dispose()
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.FlushAsync()
System.IO.Stream.ObjectInvariant()
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CanTimeout
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.MemberwiseClone(System.Boolean)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ICSharpCode.SharpZipLib.Tar
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class TarInputStream : Stream, IDisposable

Constructors

| Improve this Doc View Source

TarInputStream(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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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 Source

entryFactory

Factory used to create TarEntry or descendant class instance

Declaration
protected TarInputStream.IEntryFactory entryFactory
Field Value
Type Description
TarInputStream.IEntryFactory
| Improve this Doc View Source

entryOffset

Number of bytes read for this entry so far

Declaration
protected long entryOffset
Field Value
Type Description
System.Int64
| Improve this Doc View Source

entrySize

Size of this entry as recorded in header

Declaration
protected long entrySize
Field Value
Type Description
System.Int64
| Improve this Doc View Source

hasHitEOF

Flag set when last block has been read

Declaration
protected bool hasHitEOF
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

readBuffer

Buffer used with calls to

Read()

Declaration
protected IMemoryOwner<byte> readBuffer
Field Value
Type Description
System.Buffers.IMemoryOwner<System.Byte>
| Improve this Doc View Source

tarBuffer

Working buffer

Declaration
protected TarBuffer tarBuffer
Field Value
Type Description
TarBuffer

Properties

| Improve this Doc View Source

Available

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.

| Improve this Doc View Source

CanRead

Gets a value indicating whether the current stream supports reading

Declaration
public override bool CanRead { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanRead
| Improve this Doc View Source

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
System.IO.Stream.CanSeek
| Improve this Doc View Source

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
System.IO.Stream.CanWrite
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Length

The length in bytes of the stream

Declaration
public override long Length { get; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.Length
| Improve this Doc View Source

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
System.IO.Stream.Position
Exceptions
Type Condition
System.NotSupportedException

Any attempt to set position

| Improve this Doc View Source

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 Source

CopyEntryContents(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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
System.IO.Stream.Dispose(System.Boolean)
| Improve this Doc View Source

Flush()

Flushes the baseInputStream

Declaration
public override void Flush()
Overrides
System.IO.Stream.Flush()
| Improve this Doc View Source

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
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)
| Improve this Doc View Source

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
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
| Improve this Doc View Source

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
System.IO.Stream.ReadByte()
| Improve this Doc View Source

Reset()

Since we do not support marking just yet, we do nothing.

Declaration
public void Reset()
| Improve this Doc View Source

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
System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

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

| Improve this Doc View Source

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
System.IO.Stream.SetLength(System.Int64)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

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
System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)
Exceptions
Type Condition
System.NotSupportedException

Any access

| Improve this Doc View Source

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
System.IO.Stream.WriteByte(System.Byte)
Exceptions
Type Condition
System.NotSupportedException

Any access

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors