Class TarBuffer
The TarBuffer class implements the tar archive concept of a buffered input stream. This concept goes back to the days of blocked tape drives and special io devices. In the C# universe, the only real function that this class performs is to ensure that files have the correct "record" size, or other tars will complain.
You should never have a need to access this class directly. TarBuffers are created by Tar IO Streams.
Inheritance
Inherited Members
Namespace: ICSharpCode.SharpZipLib.Tar
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class TarBuffer
Constructors
| Improve this Doc View SourceTarBuffer()
Construct a default TarBuffer
Declaration
protected TarBuffer()
Fields
| Improve this Doc View SourceBlockSize
The size of a block in a tar archive in bytes.
Declaration
public const int BlockSize = 512
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
This is 512 bytes.
DefaultBlockFactor
The number of blocks in a default record.
Declaration
public const int DefaultBlockFactor = 20
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
The default value is 20 blocks per record.
DefaultRecordSize
The size in bytes of a default record.
Declaration
public const int DefaultRecordSize = 10240
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
The default size is 10KB.
Properties
| Improve this Doc View SourceBlockFactor
Get the Blocking factor for the buffer
Declaration
public int BlockFactor { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | This is the number of blocks in each record. |
CurrentBlock
Get the current block number, within the current record, zero based.
Declaration
public int CurrentBlock { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
Block numbers are zero based values
See Also
| Improve this Doc View SourceCurrentRecord
Get the current record number.
Declaration
public int CurrentRecord { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The current zero based record number. |
IsStreamOwner
Gets or sets a flag indicating ownership of underlying stream. When the flag is true Close() will close the underlying stream also.
Declaration
public bool IsStreamOwner { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Remarks
The default value is true.
RecordSize
Get the record size for this buffer
Declaration
public int RecordSize { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The record size in bytes. This is equal to the BlockFactor multiplied by the BlockSize |
Methods
| Improve this Doc View SourceClose()
Close the TarBuffer. If this is an output buffer, also flush the current block before closing.
Declaration
public void Close()
CloseAsync(CancellationToken)
Close the TarBuffer. If this is an output buffer, also flush the current block before closing.
Declaration
public Task CloseAsync(CancellationToken ct)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
CreateInputTarBuffer(Stream)
Create TarBuffer for reading with default BlockFactor
Declaration
public static TarBuffer CreateInputTarBuffer(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | Stream to buffer |
Returns
| Type | Description |
|---|---|
| TarBuffer | A new TarBuffer suitable for input. |
CreateInputTarBuffer(Stream, Int32)
Construct TarBuffer for reading inputStream setting BlockFactor
Declaration
public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockFactor)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | Stream to buffer |
| System.Int32 | blockFactor | Blocking factor to apply |
Returns
| Type | Description |
|---|---|
| TarBuffer | A new TarBuffer suitable for input. |
CreateOutputTarBuffer(Stream)
Construct TarBuffer for writing with default BlockFactor
Declaration
public static TarBuffer CreateOutputTarBuffer(Stream outputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | outputStream | output stream for buffer |
Returns
| Type | Description |
|---|---|
| TarBuffer | A new TarBuffer suitable for output. |
CreateOutputTarBuffer(Stream, Int32)
Construct TarBuffer for writing Tar output to streams.
Declaration
public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | outputStream | Output stream to write to. |
| System.Int32 | blockFactor | Blocking factor to apply |
Returns
| Type | Description |
|---|---|
| TarBuffer | A new TarBuffer suitable for output. |
GetBlockFactor()
Get the TAR Buffer's block factor
Declaration
[Obsolete("Use BlockFactor property instead")]
public int GetBlockFactor()
Returns
| Type | Description |
|---|---|
| System.Int32 | The block factor; the number of blocks per record. |
GetCurrentBlockNum()
Get the current block number, within the current record, zero based.
Declaration
[Obsolete("Use CurrentBlock property instead")]
public int GetCurrentBlockNum()
Returns
| Type | Description |
|---|---|
| System.Int32 | The current zero based block number. |
Remarks
The absolute block number = (record number * block factor) + block number.
GetCurrentRecordNum()
Get the current record number.
Declaration
[Obsolete("Use CurrentRecord property instead")]
public int GetCurrentRecordNum()
Returns
| Type | Description |
|---|---|
| System.Int32 | The current zero based record number. |
GetRecordSize()
Get the TAR Buffer's record size.
Declaration
[Obsolete("Use RecordSize property instead")]
public int GetRecordSize()
Returns
| Type | Description |
|---|---|
| System.Int32 | The record size in bytes. This is equal to the BlockFactor multiplied by the BlockSize |
IsEndOfArchiveBlock(Byte[])
Determine if an archive block indicates the End of an Archive has been reached. End of archive is indicated by a block that consists entirely of null bytes. All remaining blocks for the record should also be null's However some older tars only do a couple of null blocks (Old GNU tar for one) and also partial records
Declaration
public static bool IsEndOfArchiveBlock(byte[] block)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | block | The data block to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the block is an EOF block; false otherwise. |
IsEOFBlock(Byte[])
Determine if an archive block indicates End of Archive. End of archive is indicated by a block that consists entirely of null bytes. All remaining blocks for the record should also be null's However some older tars only do a couple of null blocks (Old GNU tar for one) and also partial records
Declaration
[Obsolete("Use IsEndOfArchiveBlock instead")]
public bool IsEOFBlock(byte[] block)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | block | The data block to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Returns true if the block is an EOF block; false otherwise. |
ReadBlock()
Read a block from the input stream.
Declaration
public byte[] ReadBlock()
Returns
| Type | Description |
|---|---|
| System.Byte[] | The block of data read. |
SkipBlock()
Skip over a block on the input stream.
Declaration
public void SkipBlock()
SkipBlockAsync(CancellationToken)
Skip over a block on the input stream.
Declaration
public Task SkipBlockAsync(CancellationToken ct)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
WriteBlock(Byte[])
Write a block of data to the archive.
Declaration
public void WriteBlock(byte[] block)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | block | The data to write to the archive. |
WriteBlock(Byte[], Int32)
Write an archive record to the archive, where the record may be inside of a larger array buffer. The buffer must be "offset plus record size" long.
Declaration
public void WriteBlock(byte[] buffer, int offset)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | The buffer containing the record data to write. |
| System.Int32 | offset | The offset of the record data within buffer. |
WriteBlockAsync(Byte[], Int32, CancellationToken)
Write an archive record to the archive, where the record may be inside of a larger array buffer. The buffer must be "offset plus record size" long.
Declaration
public ValueTask WriteBlockAsync(byte[] buffer, int offset, CancellationToken ct)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | The buffer containing the record data to write. |
| System.Int32 | offset | The offset of the record data within buffer. |
| System.Threading.CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.ValueTask |
WriteBlockAsync(Byte[], CancellationToken)
Write a block of data to the archive.
Declaration
public ValueTask WriteBlockAsync(byte[] block, CancellationToken ct)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | block | The data to write to the archive. |
| System.Threading.CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.ValueTask |