Convert a stream to a byte array¶
Materialize a stream into an in-memory byte array, triggered when caller materialises a read/uploaded stream for hashing, storage, or header stripping.
| Field | Value |
|---|---|
| Operation ID | OP-036 |
| Trigger | Caller materialises a read/uploaded stream for hashing, storage, or header stripping |
| Inputs | Stream |
| Outputs | byte[] |
| Primary components | FileExtensions.ToByteArray(this Stream) |
| Entry point | Common/SAIF.Common/Extensions/FileExtensions.cs |
Steps¶
- Create a
MemoryStreaminside ausingblock. (BR-057) - Copy the source stream into it with
Stream.CopyTo(the BCL method on .NET 4.6.2; the library's ownDotNet35Extensions.CopyToshim exists on disk but is excluded from compilation). - Return
memoryStream.ToArray(). The source stream is not rewound beforehand and not disposed. (BR-089)
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([ToByteArray called]) --> S1["Create MemoryStream<br>inside using block"]
S1 --> S2["Copy source stream into it<br>with Stream.CopyTo"]
S2 --> S3["Return memoryStream.ToArray();<br>source stream not disposed"]
S3 --> End([Return byte array])
Related documentation¶
Sources¶
Common/SAIF.Common/Extensions/FileExtensions.cs