Class FileFormat
Represents a file format that can be used to validate that a file's content matches its declared extension.
Namespace: FulcrumFS
Assembly: FulcrumFS.Core.dll
Syntax
public abstract class FileFormat
Remarks
Each FileFormat represents one specific file format with a fixed set of extensions. The base library provides built-in singletons for common formats accessible via static properties (Jpeg, Png, Pdf, etc.).
Content-agnostic and text-based file formats can be created using the factory methods (AnyContent(params ReadOnlySpan<string>), TextAscii(params ReadOnlySpan<string>), TextUnicode(params ReadOnlySpan<string>), TextEncoding(Encoding, params ReadOnlySpan<string>)) where the caller specifies the applicable extensions.
Custom file formats can be created by deriving from FileFormat and implementing ValidateAsync(Stream, CancellationToken).
FileFormat is independent of the FulcrumFS repository infrastructure and can be used standalone — for example, to validate user uploads in a front-end application before sending them to a service that hosts a FulcrumFS repository.
Constructors
| Name | Description |
|---|---|
| FileFormat() | Initializes a new instance of the FileFormat class. |
Properties
| Name | Description |
|---|---|
| Avi | Gets the AVI media file format. Extension: |
| Avif | Gets the AVIF image file format. Extension: |
| Bmp | Gets the BMP image file format. Extensions: |
| Doc | Gets the legacy Microsoft Word (DOC) file format. Extension: |
| Docx | Gets the DOCX (Office Open XML Word document) file format. Extension: |
| Epub | Gets the EPUB e-book file format. Extension: |
| Extensions | Gets the file extensions associated with this file format (including the leading dot, e.g., ".jpg"). |
| Flac | Gets the FLAC audio file format. Extension: |
| Gif | Gets the GIF image file format. Extension: |
| Heic | Gets the HEIC image file format. Extension: |
| Heif | Gets the HEIF image file format. Extensions: |
| Jpeg | Gets the JPEG image file format. Extensions: |
| M2ts | Gets the MPEG-TS (192-byte packet, Blu-ray style) media file format. Extensions: |
| M4a | Gets the MPEG-4 audio (M4A) media file format. Extension: |
| Mj2 | Gets the Motion JPEG 2000 (MJ2) media file format. Extension: |
| Mkv | Gets the Matroska (MKV) media file format. Extension: |
| Mov | Gets the QuickTime (MOV) media file format. Extension: |
| Mp3 | Gets the MP3 audio file format. Extension: |
| Mp4 | Gets the MP4 media file format. Extension: |
| Mpeg | Gets the MPEG-PS media file format. Extensions: |
| Name | Gets the name of the file format (e.g., "JPEG", "PDF", "TextUnicode"). |
| Odp | Gets the ODP (OpenDocument presentation) file format. Extension: |
| Ods | Gets the ODS (OpenDocument spreadsheet) file format. Extension: |
| Odt | Gets the ODT (OpenDocument text) file format. Extension: |
| Ogg | Gets the Ogg media file format. Extensions: |
Gets the PDF document file format. Extension: |
|
| Png | Gets the PNG image file format. Extensions: |
| Ppt | Gets the legacy Microsoft PowerPoint (PPT) file format. Extension: |
| Pptx | Gets the PPTX (Office Open XML presentation) file format. Extension: |
| PrimaryExtension | Gets the primary file extension associated with this file format (including the leading dot). This is the first extension in Extensions and is the extension that files of this format are written with when added to a FulcrumFS repository. |
| Rtf | Gets the RTF document file format. Extension: |
| Tg2 | Gets the 3GPP2 (3G2) media file format. Extension: |
| Tgp | Gets the 3GPP (3GP) media file format. Extension: |
| Tiff | Gets the TIFF image file format. Extensions: |
| Ts | Gets the MPEG-TS (188-byte packet) media file format. Extension: |
| Wav | Gets the WAV audio file format. Extension: |
| WebM | Gets the WebM media file format. Extension: |
| WebP | Gets the WebP image file format. Extension: |
| Xls | Gets the legacy Microsoft Excel (XLS) file format. Extension: |
| Xlsx | Gets the XLSX (Office Open XML spreadsheet) file format. Extension: |
| Zip | Gets the ZIP archive file format. Extension: |
Methods
| Name | Description |
|---|---|
| AnyContent(params ReadOnlySpan<string>) | Creates a FileFormat that accepts any content for the specified extensions. No content validation is performed beyond ensuring the file's extension is one of the specified extensions. |
| TextAscii(params ReadOnlySpan<string>) | Creates a FileFormat that validates files are valid ASCII text for the specified extensions. All bytes in the file must be in the range [0, 127] (i.e. IsValid(ReadOnlySpan<byte>) must return true). |
| TextEncoding(Encoding, params ReadOnlySpan<string>) | Creates a FileFormat that validates files decode successfully using the specified Encoding, for the specified extensions. |
| TextUnicode(UnicodeEncodings, params ReadOnlySpan<string>) | Creates a FileFormat that validates files are valid Unicode text in one of the specified encodings, for the specified extensions. |
| TextUnicode(params ReadOnlySpan<string>) | Creates a FileFormat that validates files are valid Unicode text in any encoding supported by All, for the specified extensions. |
| ToString() | Returns a string that represents the current object. |
| ValidateAsync(Stream, CancellationToken) | Validates the content of the specified stream against this file format. The stream must be seekable and positioned at 0 at the start of this call. |