Search Results for

    Show / Hide Table of Contents

    Class LocalFileStream

    Inheritance
    object
    MarshalByRefObject
    Stream
    LocalFileStream
    Implements
    IAsyncDisposable
    IFileStream
    IDisposable
    Inherited Members
    Stream.Null
    Stream.CopyTo(Stream)
    Stream.CopyToAsync(Stream)
    Stream.CopyToAsync(Stream, int)
    Stream.CopyToAsync(Stream, CancellationToken)
    Stream.FlushAsync()
    Stream.ReadAsync(byte[], int, int)
    Stream.ReadAtLeast(Span<byte>, int, bool)
    Stream.ReadAtLeastAsync(Memory<byte>, int, bool, CancellationToken)
    Stream.ReadExactly(byte[], int, int)
    Stream.ReadExactly(Span<byte>)
    Stream.ReadExactlyAsync(byte[], int, int, CancellationToken)
    Stream.ReadExactlyAsync(Memory<byte>, CancellationToken)
    Stream.Synchronized(Stream)
    Stream.WriteAsync(byte[], int, int)
    MarshalByRefObject.GetLifetimeService()
    MarshalByRefObject.InitializeLifetimeService()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Tenray.ZoneTree.AbstractFileStream
    Assembly: ZoneTree.dll
    Syntax
    public sealed class LocalFileStream : Stream, IAsyncDisposable, IFileStream, IDisposable

    Constructors

    | Improve this Doc View Source

    LocalFileStream(string, FileMode, FileAccess, FileShare, int, FileOptions)

    Declaration
    public LocalFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
    Parameters
    Type Name Description
    string path
    FileMode mode
    FileAccess access
    FileShare share
    int bufferSize
    FileOptions options

    Properties

    | Improve this Doc View Source

    CanRead

    When overridden in a derived class, gets a value indicating whether the current stream supports reading.

    Declaration
    public override bool CanRead { get; }
    Property Value
    Type Description
    bool

    true if the stream supports reading; otherwise, false.

    Overrides
    Stream.CanRead
    | Improve this Doc View Source

    CanSeek

    When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

    Declaration
    public override bool CanSeek { get; }
    Property Value
    Type Description
    bool

    true if the stream supports seeking; otherwise, false.

    Overrides
    Stream.CanSeek
    | Improve this Doc View Source

    CanTimeout

    Gets a value that determines whether the current stream can time out.

    Declaration
    public override bool CanTimeout { get; }
    Property Value
    Type Description
    bool

    A value that determines whether the current stream can time out.

    Overrides
    Stream.CanTimeout
    | Improve this Doc View Source

    CanWrite

    When overridden in a derived class, gets a value indicating whether the current stream supports writing.

    Declaration
    public override bool CanWrite { get; }
    Property Value
    Type Description
    bool

    true if the stream supports writing; otherwise, false.

    Overrides
    Stream.CanWrite
    | Improve this Doc View Source

    FilePath

    Declaration
    public string FilePath { get; }
    Property Value
    Type Description
    string
    | Improve this Doc View Source

    Length

    When overridden in a derived class, gets the length in bytes of the stream.

    Declaration
    public override long Length { get; }
    Property Value
    Type Description
    long

    A long value representing the length of the stream in bytes.

    Overrides
    Stream.Length
    Exceptions
    Type Condition
    NotSupportedException

    A class derived from Stream does not support seeking and the length is unknown.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    Position

    When overridden in a derived class, gets or sets the position within the current stream.

    Declaration
    public override long Position { get; set; }
    Property Value
    Type Description
    long

    The current position within the stream.

    Overrides
    Stream.Position
    Exceptions
    Type Condition
    IOException

    An I/O error occurs.

    NotSupportedException

    The stream does not support seeking.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    ReadTimeout

    Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

    Declaration
    public override int ReadTimeout { get; set; }
    Property Value
    Type Description
    int

    A value, in milliseconds, that determines how long the stream will attempt to read before timing out.

    Overrides
    Stream.ReadTimeout
    Exceptions
    Type Condition
    InvalidOperationException

    The ReadTimeout method always throws an InvalidOperationException.

    | Improve this Doc View Source

    WriteTimeout

    Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.

    Declaration
    public override int WriteTimeout { get; set; }
    Property Value
    Type Description
    int

    A value, in milliseconds, that determines how long the stream will attempt to write before timing out.

    Overrides
    Stream.WriteTimeout
    Exceptions
    Type Condition
    InvalidOperationException

    The WriteTimeout method always throws an InvalidOperationException.

    Methods

    | Improve this Doc View Source

    BeginRead(byte[], int, int, AsyncCallback, object)

    Begins an asynchronous read operation. (Consider using ReadAsync(byte[], int, int) instead.)

    Declaration
    public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
    Parameters
    Type Name Description
    byte[] buffer

    The buffer to read the data into.

    int offset

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

    int count

    The maximum number of bytes to read.

    AsyncCallback callback

    An optional asynchronous callback, to be called when the read is complete.

    object state

    A user-provided object that distinguishes this particular asynchronous read request from other requests.

    Returns
    Type Description
    IAsyncResult

    An IAsyncResult that represents the asynchronous read, which could still be pending.

    Overrides
    Stream.BeginRead(byte[], int, int, AsyncCallback, object)
    Exceptions
    Type Condition
    IOException

    Attempted an asynchronous read past the end of the stream, or a disk error occurs.

    ArgumentException

    One or more of the arguments is invalid.

    ObjectDisposedException

    Methods were called after the stream was closed.

    NotSupportedException

    The current Stream implementation does not support the read operation.

    | Improve this Doc View Source

    BeginWrite(byte[], int, int, AsyncCallback, object)

    Begins an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)

    Declaration
    public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
    Parameters
    Type Name Description
    byte[] buffer

    The buffer to write data from.

    int offset

    The byte offset in buffer from which to begin writing.

    int count

    The maximum number of bytes to write.

    AsyncCallback callback

    An optional asynchronous callback, to be called when the write is complete.

    object state

    A user-provided object that distinguishes this particular asynchronous write request from other requests.

    Returns
    Type Description
    IAsyncResult

    An IAsyncResult that represents the asynchronous write, which could still be pending.

    Overrides
    Stream.BeginWrite(byte[], int, int, AsyncCallback, object)
    Exceptions
    Type Condition
    IOException

    Attempted an asynchronous write past the end of the stream, or a disk error occurs.

    ArgumentException

    One or more of the arguments is invalid.

    ObjectDisposedException

    Methods were called after the stream was closed.

    NotSupportedException

    The current Stream implementation does not support the write operation.

    | Improve this Doc View Source

    Close()

    Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

    Declaration
    public override void Close()
    Overrides
    Stream.Close()
    | Improve this Doc View Source

    CopyTo(Stream, int)

    Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. Both streams positions are advanced by the number of bytes copied.

    Declaration
    public override void CopyTo(Stream destination, int bufferSize)
    Parameters
    Type Name Description
    Stream destination

    The stream to which the contents of the current stream will be copied.

    int bufferSize

    The size of the buffer. This value must be greater than zero. The default size is 81920.

    Overrides
    Stream.CopyTo(Stream, int)
    Exceptions
    Type Condition
    ArgumentNullException

    destination is null.

    ArgumentOutOfRangeException

    bufferSize is negative or zero.

    NotSupportedException

    The current stream does not support reading.

    -or-

    destination does not support writing.

    ObjectDisposedException

    Either the current stream or destination were closed before the CopyTo(Stream) method was called.

    IOException

    An I/O error occurred.

    | Improve this Doc View Source

    CopyToAsync(Stream, int, CancellationToken)

    Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. Both streams positions are advanced by the number of bytes copied.

    Declaration
    public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    Stream destination

    The stream to which the contents of the current stream will be copied.

    int bufferSize

    The size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920.

    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    Task

    A task that represents the asynchronous copy operation.

    Overrides
    Stream.CopyToAsync(Stream, int, CancellationToken)
    Exceptions
    Type Condition
    ArgumentNullException

    destination is null.

    ArgumentOutOfRangeException

    buffersize is negative or zero.

    ObjectDisposedException

    Either the current stream or the destination stream is disposed.

    NotSupportedException

    The current stream does not support reading, or the destination stream does not support writing.

    | Improve this Doc View Source

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

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

    Dispose(bool)

    Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

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

    Overrides
    Stream.Dispose(bool)
    | Improve this Doc View Source

    DisposeAsync()

    Asynchronously releases the unmanaged resources used by the Stream.

    Declaration
    public override ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask

    A task that represents the asynchronous dispose operation.

    Overrides
    Stream.DisposeAsync()
    | Improve this Doc View Source

    EndRead(IAsyncResult)

    Waits for the pending asynchronous read to complete. (Consider using ReadAsync(byte[], int, int) instead.)

    Declaration
    public override int EndRead(IAsyncResult asyncResult)
    Parameters
    Type Name Description
    IAsyncResult asyncResult

    The reference to the pending asynchronous request to finish.

    Returns
    Type Description
    int

    The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.

    Overrides
    Stream.EndRead(IAsyncResult)
    Exceptions
    Type Condition
    ArgumentNullException

    asyncResult is null.

    ArgumentException

    A handle to the pending read operation is not available.

    -or-

    The pending operation does not support reading.

    InvalidOperationException

    asyncResult did not originate from a BeginRead(byte[], int, int, AsyncCallback, object) method on the current stream.

    IOException

    The stream is closed or an internal error has occurred.

    | Improve this Doc View Source

    EndWrite(IAsyncResult)

    Ends an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)

    Declaration
    public override void EndWrite(IAsyncResult asyncResult)
    Parameters
    Type Name Description
    IAsyncResult asyncResult

    A reference to the outstanding asynchronous I/O request.

    Overrides
    Stream.EndWrite(IAsyncResult)
    Exceptions
    Type Condition
    ArgumentNullException

    asyncResult is null.

    ArgumentException

    A handle to the pending write operation is not available.

    -or-

    The pending operation does not support writing.

    InvalidOperationException

    asyncResult did not originate from a BeginWrite(byte[], int, int, AsyncCallback, object) method on the current stream.

    IOException

    The stream is closed or an internal error has occurred.

    | Improve this Doc View Source

    Flush()

    When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

    Declaration
    public override void Flush()
    Overrides
    Stream.Flush()
    Exceptions
    Type Condition
    IOException

    An I/O error occurs.

    | Improve this Doc View Source

    Flush(bool)

    Declaration
    public void Flush(bool flushToDisk)
    Parameters
    Type Name Description
    bool flushToDisk
    | Improve this Doc View Source

    FlushAsync(CancellationToken)

    Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

    Declaration
    public override Task FlushAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    Task

    A task that represents the asynchronous flush operation.

    Overrides
    Stream.FlushAsync(CancellationToken)
    Exceptions
    Type Condition
    ObjectDisposedException

    The stream has been disposed.

    | Improve this Doc View Source

    Read(byte[], int, int)

    When overridden in a derived class, reads a sequence of bytes from the current stream and advances 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
    byte[] buffer

    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.

    int offset

    The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

    int count

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

    Returns
    Type Description
    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.

    Overrides
    Stream.Read(byte[], int, int)
    Exceptions
    Type Condition
    ArgumentException

    The sum of offset and count is larger than the buffer length.

    ArgumentNullException

    buffer is null.

    ArgumentOutOfRangeException

    offset or count is negative.

    IOException

    An I/O error occurs.

    NotSupportedException

    The stream does not support reading.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    Read(Span<byte>)

    When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

    Declaration
    public override int Read(Span<byte> buffer)
    Parameters
    Type Name Description
    Span<byte> buffer

    A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.

    Returns
    Type Description
    int

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

    Overrides
    Stream.Read(Span<byte>)
    | Improve this Doc View Source

    ReadAsync(byte[], int, int, CancellationToken)

    Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

    Declaration
    public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    byte[] buffer

    The buffer to write the data into.

    int offset

    The byte offset in buffer at which to begin writing data from the stream.

    int count

    The maximum number of bytes to read.

    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    Task<int>

    A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.

    Overrides
    Stream.ReadAsync(byte[], int, int, CancellationToken)
    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null.

    ArgumentOutOfRangeException

    offset or count is negative.

    ArgumentException

    The sum of offset and count is larger than the buffer length.

    NotSupportedException

    The stream does not support reading.

    ObjectDisposedException

    The stream has been disposed.

    InvalidOperationException

    The stream is currently in use by a previous read operation.

    | Improve this Doc View Source

    ReadAsync(Memory<byte>, CancellationToken)

    Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

    Declaration
    public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    Memory<byte> buffer

    The region of memory to write the data into.

    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    ValueTask<int>

    A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into the buffer. The result value can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or it can be 0 (zero) if the end of the stream has been reached.

    Overrides
    Stream.ReadAsync(Memory<byte>, CancellationToken)
    | Improve this Doc View Source

    ReadByte()

    Reads a byte from the stream and advances 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
    int

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

    Overrides
    Stream.ReadByte()
    Exceptions
    Type Condition
    NotSupportedException

    The stream does not support reading.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    ReadFaster(byte[], int, int)

    Custom ReadExactly method that does not use internal buffer.

    Declaration
    public int ReadFaster(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    byte[] buffer
    int offset
    int count
    Returns
    Type Description
    int
    | Improve this Doc View Source

    Seek(long, SeekOrigin)

    When overridden in a derived class, sets the position within the current stream.

    Declaration
    public override long Seek(long offset, SeekOrigin origin)
    Parameters
    Type Name Description
    long offset

    A byte offset relative to the origin parameter.

    SeekOrigin origin

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

    Returns
    Type Description
    long

    The new position within the current stream.

    Overrides
    Stream.Seek(long, SeekOrigin)
    Exceptions
    Type Condition
    IOException

    An I/O error occurs.

    NotSupportedException

    The stream does not support seeking, such as if the stream is constructed from a pipe or console output.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    SetLength(long)

    When overridden in a derived class, sets the length of the current stream.

    Declaration
    public override void SetLength(long value)
    Parameters
    Type Name Description
    long value

    The desired length of the current stream in bytes.

    Overrides
    Stream.SetLength(long)
    Exceptions
    Type Condition
    IOException

    An I/O error occurs.

    NotSupportedException

    The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.

    ObjectDisposedException

    Methods were called after the stream was closed.

    | Improve this Doc View Source

    ToStream()

    Declaration
    public Stream ToStream()
    Returns
    Type Description
    Stream
    | Improve this Doc View Source

    Write(byte[], int, int)

    When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

    Declaration
    public override void Write(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    byte[] buffer

    An array of bytes. This method copies count bytes from buffer to the current stream.

    int offset

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

    int count

    The number of bytes to be written to the current stream.

    Overrides
    Stream.Write(byte[], int, int)
    Exceptions
    Type Condition
    ArgumentException

    The sum of offset and count is greater than the buffer length.

    ArgumentNullException

    buffer is null.

    ArgumentOutOfRangeException

    offset or count is negative.

    IOException

    An I/O error occurred, such as the specified file cannot be found.

    NotSupportedException

    The stream does not support writing.

    ObjectDisposedException

    Write(byte[], int, int) was called after the stream was closed.

    | Improve this Doc View Source

    Write(ReadOnlySpan<byte>)

    When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

    Declaration
    public override void Write(ReadOnlySpan<byte> buffer)
    Parameters
    Type Name Description
    ReadOnlySpan<byte> buffer

    A region of memory. This method copies the contents of this region to the current stream.

    Overrides
    Stream.Write(ReadOnlySpan<byte>)
    | Improve this Doc View Source

    WriteAsync(byte[], int, int, CancellationToken)

    Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

    Declaration
    public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    byte[] buffer

    The buffer to write data from.

    int offset

    The zero-based byte offset in buffer from which to begin copying bytes to the stream.

    int count

    The maximum number of bytes to write.

    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    Task

    A task that represents the asynchronous write operation.

    Overrides
    Stream.WriteAsync(byte[], int, int, CancellationToken)
    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null.

    ArgumentOutOfRangeException

    offset or count is negative.

    ArgumentException

    The sum of offset and count is larger than the buffer length.

    NotSupportedException

    The stream does not support writing.

    ObjectDisposedException

    The stream has been disposed.

    InvalidOperationException

    The stream is currently in use by a previous write operation.

    | Improve this Doc View Source

    WriteAsync(ReadOnlyMemory<byte>, CancellationToken)

    Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

    Declaration
    public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    ReadOnlyMemory<byte> buffer

    The region of memory to write data from.

    CancellationToken cancellationToken

    The token to monitor for cancellation requests. The default value is None.

    Returns
    Type Description
    ValueTask

    A task that represents the asynchronous write operation.

    Overrides
    Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
    | Improve this Doc View Source

    WriteByte(byte)

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

    Declaration
    public override void WriteByte(byte value)
    Parameters
    Type Name Description
    byte value

    The byte to write to the stream.

    Overrides
    Stream.WriteByte(byte)
    Exceptions
    Type Condition
    IOException

    An I/O error occurs.

    NotSupportedException

    The stream does not support writing, or the stream is already closed.

    ObjectDisposedException

    Methods were called after the stream was closed.

    Implements

    IAsyncDisposable
    IFileStream
    IDisposable
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2022 Tenray.io