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
stringThe name of the target file.
mode
FileModeThe 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
CanSeek
Gets a value indicating whether the underlying temporary file stream supports seeking.
public override bool CanSeek { get; }
Property Value
CanWrite
Gets a value indicating whether the underlying temporary file stream supports writing.
public override bool CanWrite { get; }
Property Value
Length
Gets the length in bytes of the underlying temporary file stream.
public override long Length { get; }
Property Value
Position
Gets or sets the current position within the underlying temporary file stream.
public override long Position { get; set; }
Property Value
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
booltrue 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
intThe byte offset in buffer at which to begin storing the data read from the underlying stream.
count
intThe 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
longA byte offset relative to the origin parameter.
origin
SeekOriginA 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
longThe 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)