Table of Contents

Class TransactionFileStream

Namespace
Ecng.Serialization
Assembly
Ecng.Serialization.dll

Represents a transactional file stream that writes data to a temporary file and, upon disposal, commits the changes to the target file.

public class TransactionFileStream : Stream, IDisposable, IAsyncDisposable
Inheritance
TransactionFileStream
Implements
Inherited Members
Extension Methods

Constructors

TransactionFileStream(string, FileMode)

Initializes a new instance of the TransactionFileStream class.

public TransactionFileStream(string name, FileMode mode)

Parameters

name string

The name of the target file.

mode FileMode

The file mode that specifies the type of operations to be performed on the file.

Properties

CanRead

Gets a value indicating whether the temporary file stream supports reading. Always returns false.

public override bool CanRead { get; }

Property Value

bool

CanSeek

Gets a value indicating whether the underlying temporary file stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

CanWrite

Gets a value indicating whether the underlying temporary file stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

Length

Gets the length in bytes of the underlying temporary file stream.

public override long Length { get; }

Property Value

long

Position

Gets or sets the current position within the underlying temporary file stream.

public override long Position { get; set; }

Property Value

long

Methods

Dispose(bool)

Releases the unmanaged resources used by the TransactionFileStream and optionally releases the managed resources. Copies the temporary file to the target file and then deletes the temporary file.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Flush()

Clears all buffers for the current stream and causes any buffered data to be written to the underlying file.

public override void Flush()

Read(byte[], int, int)

Reading is not supported by the TransactionFileStream.

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The buffer to read data into.

offset int

The byte offset in buffer at which to begin storing the data read from the underlying stream.

count int

The maximum number of bytes to be read from the underlying stream.

Returns

int

This method always throws a NotSupportedException.

Exceptions

NotSupportedException

Always thrown.

Seek(long, SeekOrigin)

Sets the position within the temporary file stream.

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

A byte offset relative to the origin parameter.

origin SeekOrigin

A value of type SeekOrigin indicating the reference point used to obtain the new position.

Returns

long

The new position within the temporary file stream.

SetLength(long)

Sets the length of the underlying temporary file stream.

public override void SetLength(long value)

Parameters

value long

The desired length of the current stream in bytes.

Write(byte[], int, int)

Writes a sequence of bytes to the temporary file stream.

public override void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

An array of bytes. This is the buffer that contains the data to write to the temporary file.

offset int

The zero-based byte offset in buffer at which to begin copying bytes to the temporary file.

count int

The number of bytes to be written to the temporary file.