CompoundStreamBuilder Class
Definition
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
namestringThe entry name.
openReadFunc<Stream>A factory that opens a readable stream over the payload each time it is invoked.
lengthlongThe payload length, in bytes.
Returns
- CompoundStreamBuilder
A new deferred CompoundStreamBuilder.
Exceptions
- ArgumentNullException
Thrown when
openReadis null.- ArgumentOutOfRangeException
Thrown when
lengthis negative.- CompoundFileSerializationException
Thrown when
nameis 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
Returns
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- CompoundFileSerializationException
Thrown when
nameis 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
namestringThe entry name.
contentReadOnlyMemory<byte>The payload bytes.
Returns
Exceptions
- CompoundFileSerializationException
Thrown when
nameis 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
namestringThe entry name.
textstringThe text to encode.
encodingEncodingThe encoding to apply; defaults to UTF-8.
Returns
Exceptions
- ArgumentNullException
Thrown when
textis null.- CompoundFileSerializationException
Thrown when
nameis 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
Returns
- CompoundStreamBuilder
A new deferred CompoundStreamBuilder.
Exceptions
- ArgumentNullException
Thrown when
pathis null.- CompoundFileSerializationException
Thrown when
nameis 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
contentReadOnlySpan<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
Exceptions
- ArgumentNullException
Thrown when
textis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |