Class SandboxedFileReader
Represents a read-only access to a file on the file system.
Implements
Inherited Members
Namespace: DevToys.Api
Assembly: DevToys.Api.dll
Syntax
public abstract class SandboxedFileReader : IDisposable
Remarks
The file can be read and accessed multiple times in parallel. In some cases, the file's resulting stream is non-seekable. Disposing the SandboxedFileReader will close the access to the file.
Constructors
SandboxedFileReader(string)
Initializes a new instance of the SandboxedFileReader class.
Declaration
protected SandboxedFileReader(string fileName)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | The name of the file, including its extension. |
Fields
BufferSize
The buffer size used for reading the file in chunks.
Declaration
public const int BufferSize = 4096
Field Value
Type | Description |
---|---|
int |
Properties
FileName
Gets or sets the name of the file, including its extension.
Declaration
public string FileName { get; init; }
Property Value
Type | Description |
---|---|
string |
Methods
CopyFileContentToAsync(Stream, CancellationToken)
Copies the content of the file to the given stream.
Declaration
public Task CopyFileContentToAsync(Stream destinationStream, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Stream | destinationStream | The destination stream. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The SandboxedFileReader has been disposed. |
Dispose()
Disposes the SandboxedFileReader and releases any resources used.
Declaration
public void Dispose()
FromFileInfo(FileInfo)
Creates a new instance of the SandboxedFileReader class from a FileInfo object.
Declaration
public static SandboxedFileReader FromFileInfo(FileInfo fileInfo)
Parameters
Type | Name | Description |
---|---|---|
FileInfo | fileInfo | The FileInfo object representing the file. |
Returns
Type | Description |
---|---|
SandboxedFileReader | A new instance of the SandboxedFileReader class. |
GetNewAccessToFileContentAsync(CancellationToken)
Gets a new stream that can be used to read the file. The stream gets disposed automatically when the SandboxedFileReader is disposed.
Declaration
public Task<Stream> GetNewAccessToFileContentAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<Stream> | A task representing the asynchronous operation. |
Remarks
In some cases, the returned stream is non-seekable.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The SandboxedFileReader has been disposed. |
OpenReadFileAsync(CancellationToken)
Opens the file for reading asynchronously.
Declaration
protected abstract ValueTask<Stream> OpenReadFileAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
ValueTask<Stream> | A task representing the asynchronous operation. |
Events
Disposed
Raised when the SandboxedFileReader is disposed.
Declaration
public event EventHandler? Disposed
Event Type
Type | Description |
---|---|
EventHandler |