IFile Interface
Represents a file. Not all implementations will support all available methods and may throw System.NotSupportedException.
graph BT Type-.->Interface0["IFileSystemEntry"] click Interface0 "/api/Statiq.Common/IFileSystemEntry" Type-.->Interface1["IDisplayable"] click Interface1 "/api/Statiq.Common/IDisplayable" Type-.->Interface2["IContentProviderFactory"] click Interface2 "/api/Statiq.Common/IContentProviderFactory" Type-.->Interface3["ICacheCode"] click Interface3 "/api/Statiq.Common/ICacheCode" Type["IFile"] class Type type-node Implementing0["TestFile"]-.->Type click Implementing0 "/api/Statiq.Testing/TestFile"

Syntax

public interface IFile : IFileSystemEntry, IDisplayable, IContentProviderFactory, ICacheCode

Properties

Name Property Type Summary
Directory IDirectory
Gets the directory of the file.
Length long
Gets the length of the file.
MediaType string
Gets the media type of the file.
Path NormalizedPath
Gets the path to the file.

Methods

Name Return Value Summary
Delete() void
Deletes the file.
Open(bool) Stream
Opens the file for reading and writing. This will either create the file if it doesn't exist or overwrite it if it does.
OpenAppend(bool) Stream
Opens the file for writing. This will either create the file if it doesn't exist or append to it if it does.
OpenRead() Stream
Opens the file for reading. If it does not exist, an exception will be thrown.
OpenText() TextReader
Opens the file for reading as text. If it does not exist, an exception will be thrown.
OpenWrite(bool) Stream
Opens the file for writing. This will either create the file if it doesn't exist or overwrite it if it does. You must manually call System.IO.Stream.SetLength(System.Int64) when done to ensure previously existing data is truncated.
ReadAllBytesAsync(CancellationToken) Task<byte[]>
Reads all bytes from the file.
ReadAllTextAsync(CancellationToken) Task<string>
Reads all text from the file.
Refresh() void
Refreshes any cached information about the file.
WriteAllBytesAsync(byte[], bool, CancellationToken) Task
Writes the specified bytes to a file.
WriteAllTextAsync(string, bool, CancellationToken) Task
Writes the specified text to a file.

Extension Methods

Name Value Summary
AppendFromAsync(Stream, bool, CancellationToken) Task
Copies from a source stream to a file, appending to the end of the file.
CopyToAsync(IFile, bool, bool, CancellationToken) Task
Copies the file to the specified destination file, truncating any remaining data in the destination file.
CopyToAsync(Stream, CancellationToken) Task
Copies from a file to a destination stream.
DeserializeJsonAsync(Type, JsonSerializerOptions, CancellationToken) ValueTask<object>
DeserializeJsonAsync<TValue>(JsonSerializerOptions, CancellationToken) ValueTask<TValue>
DeserializeYaml(Type) object
DeserializeYaml<TValue>() TValue
MoveToAsync(IFile, CancellationToken) Task
Moves the file to the specified destination file, truncating any remaining data in the destination file.
SerializeJsonAsync(object, Type, bool, JsonSerializerOptions, CancellationToken) Task
SerializeJsonAsync(object, Type, JsonSerializerOptions, CancellationToken) Task
SerializeJsonAsync<TValue>(TValue, bool, JsonSerializerOptions, CancellationToken) Task
SerializeJsonAsync<TValue>(TValue, JsonSerializerOptions, CancellationToken) Task
SerializeYaml(object, bool) void
SerializeYaml(object, Type, bool) void
SerializeYaml(object, Type) void
SerializeYaml(object) void
SerializeYaml<TValue>(TValue, bool) void
SerializeYaml<TValue>(TValue) void
ThrowIfNull<IFile>(string) T
ToDocument<IFile>(IContentProvider) IDocument
ToDocument<IFile>(IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToDocument<IFile>(NormalizedPath, IContentProvider) IDocument
ToDocument<IFile>(NormalizedPath, IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToDocument<IFile>(NormalizedPath, NormalizedPath, IContentProvider) IDocument
ToDocument<IFile>(NormalizedPath, NormalizedPath, IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToSafeDisplayString() string
A safe display string that can be used for logging and returns "null" when the underlying object is null.
WriteFromAsync(Stream, bool, bool, CancellationToken) Task
Copies from a source stream to a file, truncating any remaining data in the destination file.