Show / Hide Table of Contents

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
System.Object
System.MarshalByRefObject
System.IO.Stream
TarOutputStream
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.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 TarOutputStream : Stream, IDisposable

Constructors

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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 Source

assemblyBuffer

'Assembly' buffer used to assemble data before writing

Declaration
protected byte[] assemblyBuffer
Field Value
Type Description
System.Byte[]
| Improve this Doc View Source

blockBuffer

single block working buffer

Declaration
protected byte[] blockBuffer
Field Value
Type Description
System.Byte[]
| Improve this Doc View Source

buffer

TarBuffer used to provide correct blocking factor

Declaration
protected TarBuffer buffer
Field Value
Type Description
TarBuffer
| Improve this Doc View Source

currSize

Size for the current entry

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

nameEncoding

name encoding

Declaration
protected Encoding nameEncoding
Field Value
Type Description
System.Text.Encoding
| Improve this Doc View Source

outputStream

the destination stream for the archive contents

Declaration
protected Stream outputStream
Field Value
Type Description
System.IO.Stream

Properties

| Improve this Doc View Source

CanRead

true if the stream supports reading; otherwise, false.

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

CanSeek

true if the stream supports seeking; otherwise, false.

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

CanWrite

true if stream supports writing; otherwise, false.

Declaration
public override bool CanWrite { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanWrite
| 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

length of stream in bytes

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 current stream.

Declaration
public override long Position { get; set; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.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

CloseEntry()

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

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

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
System.IO.Stream.Dispose(System.Boolean)
Remarks

This means that Finish() is called followed by calling the TarBuffer's Close().

| Improve this Doc View Source

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

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

Flush()

All buffered data is written to destination

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

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
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
| 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

The TarBuffer record size.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

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 count requested if data is not available.

Overrides
System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)
| Improve this Doc View Source

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 count requested if data is not available.

Overrides
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
| Improve this Doc View Source

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

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 origin to seek to

System.IO.SeekOrigin origin

The System.IO.SeekOrigin to seek from.

Returns
Type Description
System.Int64

The new position in the stream.

Overrides
System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)
| Improve this Doc View Source

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

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

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

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.

Overrides
System.IO.Stream.WriteByte(System.Byte)

Implements

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