Class BinaryFile
Represents a binary file.
public sealed class BinaryFile : ValueObject
- Inheritance
-
BinaryFile
- Inherited Members
Constructors
BinaryFile(byte[])
Initializes a new instance of the BinaryFile class.
public BinaryFile(byte[] content)
Parameters
contentbyte[]Content.
BinaryFile(byte[], string?, IReadOnlyDictionary<string, object>?)
Initializes a new instance of the BinaryFile class.
public BinaryFile(byte[] content, string? mimeType, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
contentbyte[]Content.
mimeTypestringMime type.
metadataIReadOnlyDictionary<string, object>Metadata.
BinaryFile(string?, byte[], string?, IReadOnlyDictionary<string, object>?)
Initializes a new instance of the BinaryFile class.
public BinaryFile(string? name, byte[] content, string? mimeType = null, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
namestringName.
contentbyte[]Content.
mimeTypestringMime type.
metadataIReadOnlyDictionary<string, object>Metadata.
Fields
OctetStreamMimeType
Represents the (default) MIME type for binary data streams.
public const string OctetStreamMimeType = "application/octet-stream"
Field Value
Remarks
This constant is commonly used to specify the MIME type for generic binary data when no specific format is applicable.
PdfMimeType
Represents the MIME type for PDF files.
public const string PdfMimeType = "application/pdf"
Field Value
Remarks
This constant can be used to specify or validate the MIME type for PDF documents in scenarios such as HTTP headers, file uploads, or content type checks.
Properties
Content
Gets the content.
public byte[] Content { get; init; }
Property Value
- byte[]
Empty
Gets an empty binary file.
public static BinaryFile Empty { get; }
Property Value
Metadata
Gets the file metadata.
public IReadOnlyDictionary<string, object> Metadata { get; init; }
Property Value
MimeType
Gets the document mime type.
public string MimeType { get; }
Property Value
Name
Gets the file name with extension.
public string? Name { get; init; }
Property Value
Methods
GetEqualityComponents()
Gets equality components.
protected override IEnumerable<object?> GetEqualityComponents()
Returns
- IEnumerable<object>
The components.
WithMetadata(string, object)
Adds a metadata to binary file.
public BinaryFile WithMetadata(string key, object value)
Parameters
Returns
- BinaryFile
The new instance.
WithMimeType(string)
Sets the MIME type.
public BinaryFile WithMimeType(string mimeType)
Parameters
mimeTypestringThe MIME type.
Returns
- BinaryFile
The same instance if MIME type is up to date or if previous MIME type is application/octet-stream, a new instance otherwise.
WithName(string?)
Sets the name.
public BinaryFile WithName(string? name)
Parameters
namestringThe file name.
Returns
- BinaryFile
The same instance if name is up to date, a new instance otherwise.