Table of Contents

CompoundStreamBuilder Class

Definition

Namespace
Bodu.IO.Compound.Builders
Assembly
Bodu.IO.Compound.dll
Package
Bodu.IO.Compound 1.0.0
Source
CompoundStreamBuilder.cs

Represents a stream entry in a mutable compound-file object model - a named, file-like node carrying an opaque byte payload.

public sealed class CompoundStreamBuilder : CompoundEntryBuilder
Inheritance
CompoundStreamBuilder
Inherited Members
Extension Methods

Remarks

This is the authoring counterpart of CompoundStream and the compound-file analogue of a JsonValue leaf.

A stream node is either in-memory, holding its bytes directly, or deferred, holding a re-openable source (a file or a stream factory) of a known length. A deferred node lets large payloads be streamed straight to the output during serialization without ever being held in memory; reading Content on such a node materializes it.

Properties

Content

Gets or sets the byte payload of the stream.

public ReadOnlyMemory<byte> Content { get; set; }

Property Value

ReadOnlyMemory<byte>

The stream's content.

Remarks

Reading this property on a deferred node opens and reads its source fully into memory; thereafter the node is in-memory. Setting the property replaces the payload and makes the node in-memory.

EntryType

Gets the kind of entry this node represents.

public override CompoundEntryType EntryType { get; }

Property Value

CompoundEntryType

The CompoundEntryType of the node.

Length

Gets the length, in bytes, of the stream payload.

public long Length { get; }

Property Value

long

The payload length; reported without opening a deferred source.

Methods

Create(string, Func<Stream>, long)

Creates a deferred stream node whose payload is read on demand from a re-openable source.

public static CompoundStreamBuilder Create(string name, Func<Stream> openRead, long length)

Parameters

name string

The entry name.

openRead Func<Stream>

A factory that opens a readable stream over the payload each time it is invoked.

length long

The payload length, in bytes.

Returns

CompoundStreamBuilder

A new deferred CompoundStreamBuilder.

Exceptions

ArgumentNullException

Thrown when openRead is null.

ArgumentOutOfRangeException

Thrown when length is negative.

CompoundFileSerializationException

Thrown when name is invalid.

Create(string, Stream)

Creates a stream node whose payload is read from the supplied stream.

public static CompoundStreamBuilder Create(string name, Stream source)

Parameters

name string

The entry name.

source Stream

The stream to read to its end.

Returns

CompoundStreamBuilder

A new CompoundStreamBuilder.

Exceptions

ArgumentNullException

Thrown when source is null.

CompoundFileSerializationException

Thrown when name is invalid.

Create(string, ReadOnlyMemory<byte>)

Creates a stream node with the specified name and payload.

public static CompoundStreamBuilder Create(string name, ReadOnlyMemory<byte> content)

Parameters

name string

The entry name.

content ReadOnlyMemory<byte>

The payload bytes.

Returns

CompoundStreamBuilder

A new CompoundStreamBuilder.

Exceptions

CompoundFileSerializationException

Thrown when name is invalid.

Create(string, string, Encoding?)

Creates a stream node whose payload is the encoded form of the supplied text.

public static CompoundStreamBuilder Create(string name, string text, Encoding? encoding = null)

Parameters

name string

The entry name.

text string

The text to encode.

encoding Encoding

The encoding to apply; defaults to UTF-8.

Returns

CompoundStreamBuilder

A new CompoundStreamBuilder.

Exceptions

ArgumentNullException

Thrown when text is null.

CompoundFileSerializationException

Thrown when name is invalid.

CreateFromFile(string, string)

Creates a deferred stream node whose payload is read on demand from a file.

public static CompoundStreamBuilder CreateFromFile(string name, string path)

Parameters

name string

The entry name.

path string

The path of the file providing the payload.

Returns

CompoundStreamBuilder

A new deferred CompoundStreamBuilder.

Exceptions

ArgumentNullException

Thrown when path is null.

CompoundFileSerializationException

Thrown when name is invalid.

DeepClone()

Creates a deep, detached copy of this node and its descendants.

public override CompoundEntryBuilder DeepClone()

Returns

CompoundEntryBuilder

An independent copy with no parent.

SetContent(ReadOnlySpan<byte>)

Replaces the stream payload with the supplied bytes.

public void SetContent(ReadOnlySpan<byte> content)

Parameters

content ReadOnlySpan<byte>

The new payload, copied into the node.

SetContent(string, Encoding?)

Replaces the stream payload with the encoded form of the supplied text.

public void SetContent(string text, Encoding? encoding = null)

Parameters

text string

The text to encode.

encoding Encoding

The encoding to apply; defaults to UTF-8.

Exceptions

ArgumentNullException

Thrown when text is null.

Applies to

ProductVersions
.NET8, 10