<PackageReference Include="System.Memory.Data" Version="10.0.0-rc.1.25451.107" />

BinaryData

public class BinaryData
A lightweight abstraction for a payload of bytes that supports converting between string, stream, JSON, and bytes.
public static BinaryData Empty { get; }

Returns an empty BinaryData.

public bool IsEmpty { get; }

Gets a value that indicates whether this data is empty.

public int Length { get; }

Gets the number of bytes of this data.

public string MediaType { get; }

public BinaryData(byte[] data)

Creates a BinaryData instance by wrapping the provided byte array.

public BinaryData(byte[] data, string mediaType)

public BinaryData(object jsonSerializable, JsonSerializerOptions options = null, Type type = null)

Creates a BinaryData instance by serializing the provided object to JSON using JsonSerializer.

public BinaryData(object jsonSerializable, JsonSerializerContext context, Type type = null)

Creates a BinaryData instance by serializing the provided object to JSON using JsonSerializer.

public BinaryData(ReadOnlyMemory<byte> data)

Creates a BinaryData instance by wrapping the provided bytes.

public BinaryData(ReadOnlyMemory<byte> data, string mediaType)

public BinaryData(string data)

Creates a BinaryData instance from a string by converting the string to bytes using the UTF-8 encoding.

public BinaryData(string data, string mediaType)

public static BinaryData FromBytes(ReadOnlyMemory<byte> data)

Creates a BinaryData instance by wrapping the provided ReadOnlyMemory<T>.

public static BinaryData FromBytes(ReadOnlyMemory<byte> data, string mediaType)

public static BinaryData FromBytes(byte[] data)

Creates a BinaryData instance by wrapping the provided byte array.

public static BinaryData FromBytes(byte[] data, string mediaType)

public static BinaryData FromFile(string path)

public static BinaryData FromFile(string path, string mediaType)

public static Task<BinaryData> FromFileAsync(string path, CancellationToken cancellationToken = default)

public static Task<BinaryData> FromFileAsync(string path, string mediaType, CancellationToken cancellationToken = default)

public static BinaryData FromObjectAsJson<T>(T jsonSerializable, JsonSerializerOptions options = null)

Creates a BinaryData instance by serializing the provided object using the JsonSerializer.

public static BinaryData FromObjectAsJson<T>(T jsonSerializable, JsonTypeInfo<T> jsonTypeInfo)

Creates a BinaryData instance by serializing the provided object using the JsonSerializer.

public static BinaryData FromStream(Stream stream)

Creates a BinaryData instance from the specified stream. The stream is not disposed by this method.

public static BinaryData FromStream(Stream stream, string mediaType)

public static Task<BinaryData> FromStreamAsync(Stream stream, CancellationToken cancellationToken = default)

Creates a BinaryData instance from the specified stream. The stream is not disposed by this method.

public static Task<BinaryData> FromStreamAsync(Stream stream, string mediaType, CancellationToken cancellationToken = default)

public static BinaryData FromString(string data)

Creates a BinaryData instance from a string by converting the string to bytes using the UTF-8 encoding.

public static BinaryData FromString(string data, string mediaType)

public static ReadOnlyMemory<byte> op_Implicit(BinaryData data)

Defines an implicit conversion from a BinaryData to a ReadOnlyMemory<T>.

public static ReadOnlySpan<byte> op_Implicit(BinaryData data)

Defines an implicit conversion from a BinaryData to a ReadOnlySpan<T>.

public byte[] ToArray()

Converts the BinaryData to a byte array.

public ReadOnlyMemory<byte> ToMemory()

Gets the value of this instance as bytes without any further interpretation.

public T ToObjectFromJson<T>(JsonSerializerOptions options = null)

Converts the BinaryData to the specified type using JsonSerializer.

public T ToObjectFromJson<T>(JsonTypeInfo<T> jsonTypeInfo)

Converts the BinaryData to the specified type using JsonSerializer.

public Stream ToStream()

Converts the BinaryData to a read-only stream.

public BinaryData WithMediaType(string mediaType)