Skip to content

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

  1. Create a MemoryStream inside a using block. (BR-057)
  2. Copy the source stream into it with Stream.CopyTo (the BCL method on .NET 4.6.2; the library's own DotNet35Extensions.CopyTo shim exists on disk but is excluded from compilation).
  3. 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])

Sources

  • Common/SAIF.Common/Extensions/FileExtensions.cs