Skip to content

OffsetStream Class

Wraps a source stream and offsets all read/write/seek calls by a given value.

MethodDescription
Close()Closes the underlying stream.
Flush()Flushes the source stream.
Read(buffer, offset, count)Reads a sequence of bytes from the source stream and advances the position within the stream by the number of bytes read.
ReadByte()Reads a byte from the stream and advances the position within the source stream by one byte, or returns -1 if at the end of the stream.
Seek(offset, origin)Sets the position within the current stream, which is equal to the position within the source stream minus the offset.
SetLength(value)Sets the effective length of the stream, which is equal to the length of the source stream minus the offset.
Write(buffer, offset, count)Writes a sequence of bytes to the source stream and advances the current position within this stream by the number of bytes written.
WriteByte(value)Writes a byte to the current position in the source stream and advances the position within the stream by one byte.
PropertyDescription
CanReadGets a value indicating whether the source stream supports reading.
CanSeekGets a value indicating whether the source stream supports seeking.
CanWriteGets a value indicating whether the source stream supports writing.
LengthGets the effective length of the stream, which is equal to the length of the source stream minus the offset.
OffsetGets the number of bytes to offset all calls before redirecting to the underlying stream.
PositionGets or sets the effective position of the stream, which is equal to the position of the source stream minus the offset.
SourceGets the underlying stream that this OffsetStream calls into.

This class is used to trick archive an packing or unpacking process into reading or writing at an offset into a file, primarily for self-extracting packages. WixToolset.Dtf.Compression.dll version 5.0.0+41e11442b2ca93e444b60213b5ae99dcbab787d8

Closes the underlying stream.

public void Close()

Flushes the source stream.

public void Flush()

Reads a sequence of bytes from the source stream and advances the position within the stream by the number of bytes read.

public int Read(
System.Byte[] buffer,
int offset,
int count
)
ParameterTypeDescription
bufferSystem.Byte[]An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offsetintThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countintThe maximum number of bytes to be read from the current stream.

int The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

Reads a byte from the stream and advances the position within the source stream by one byte, or returns -1 if at the end of the stream.

public int ReadByte()

int The unsigned byte cast to an Int32, or -1 if at the end of the stream.

Sets the position within the current stream, which is equal to the position within the source stream minus the offset.

public System.Int64 Seek(
System.Int64 offset,
System.IO.SeekOrigin origin
)
ParameterTypeDescription
offsetSystem.Int64A byte offset relative to the origin parameter.
originSystem.IO.SeekOriginA value of type SeekOrigin indicating the reference point used to obtain the new position.

System.Int64 The new position within the current stream.

Sets the effective length of the stream, which is equal to the length of the source stream minus the offset.

public void SetLength(
System.Int64 value
)
ParameterTypeDescription
valueSystem.Int64The desired length of the current stream in bytes.

Writes a sequence of bytes to the source stream and advances the current position within this stream by the number of bytes written.

public void Write(
System.Byte[] buffer,
int offset,
int count
)
ParameterTypeDescription
bufferSystem.Byte[]An array of bytes. This method copies count bytes from buffer to the current stream.
offsetintThe zero-based byte offset in buffer at which to begin copying bytes to the current stream.
countintThe number of bytes to be written to the current stream.

Writes a byte to the current position in the source stream and advances the position within the stream by one byte.

public void WriteByte(
System.Byte value
)
ParameterTypeDescription
valueSystem.ByteThe byte to write to the stream.

Gets a value indicating whether the source stream supports reading.

public bool CanRead { get; set; }

Gets a value indicating whether the source stream supports seeking.

public bool CanSeek { get; set; }

Gets a value indicating whether the source stream supports writing.

public bool CanWrite { get; set; }

Gets the effective length of the stream, which is equal to the length of the source stream minus the offset.

public System.Int64 Length { get; set; }

Gets the number of bytes to offset all calls before redirecting to the underlying stream.

public System.Int64 Offset { get; set; }

Gets or sets the effective position of the stream, which is equal to the position of the source stream minus the offset.

public System.Int64 Position { get; set; }

Gets the underlying stream that this OffsetStream calls into.

public System.IO.Stream Source { get; set; }