Show / Hide Table of Contents

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
System.Object
TarBuffer
Inherited Members
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 TarBuffer

Constructors

| Improve this Doc View Source

TarBuffer()

Construct a default TarBuffer

Declaration
protected TarBuffer()

Fields

| Improve this Doc View Source

BlockSize

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

BlockFactor

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.

| Improve this Doc View Source

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

CurrentRecord

Get the current record number.

Declaration
public int CurrentRecord { get; }
Property Value
Type Description
System.Int32

The current zero based record number.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

Close()

Close the TarBuffer. If this is an output buffer, also flush the current block before closing.

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

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

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ReadBlock()

Read a block from the input stream.

Declaration
public byte[] ReadBlock()
Returns
Type Description
System.Byte[]

The block of data read.

| Improve this Doc View Source

SkipBlock()

Skip over a block on the input stream.

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

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

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

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
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors