Read a stream into bytes¶
This internal helper materializes an already-open Stream as a Byte() array so the stream overloads of SendMailWithAttachment can pass it to the SOAP proxy. Unlike GetFileAsBytes, it treats a missing stream as a normal, non-exceptional case: a Nothing input simply produces a Nothing result.
| Field | Value |
|---|---|
| Operation ID | MAIL-OP-006 |
| Trigger | Attachment-sending code calls GetStreamAsBytes(inStream). |
| Inputs | inStream. |
| Outputs | A Byte() payload, or Nothing. |
| Primary components | Mail.GetStreamAsBytes, System.IO.Stream |
| Entry point | SAIF.Framework.Mail\MailServices.vb |
Steps¶
- Initialize the local
bytesvariable toNothing. - Test whether
inStream Is Nothing(BR-005). - If it is
Nothing, skip allocation entirely and returnNothingto the caller (BR-005). - When a stream is present, allocate the buffer with
ReDim bytes(CInt(inStream.Length)). - Read
inStream.Lengthbytes starting from the stream's current position into the allocated array. - Return the populated byte array to the caller.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([GetStreamAsBytes call]) --> Check{Stream is Nothing?}
Check -->|Yes| ReturnNothing[Return Nothing]
Check -->|No| Allocate[Allocate byte array]
Allocate --> Read[Read stream into array]
Read --> ReturnBytes[Return byte array]
Failure and edge-case behavior¶
- A
Nothinginput stream is an accepted, expected case rather than an error condition; no exception is raised. - The helper never rewinds the stream to position zero before reading, so whatever the stream's current read position happens to be determines which bytes end up in the returned array — a previously partially-read stream yields a partially-populated payload.
ReDim bytes(CInt(inStream.Length))allocates one element more thaninStream.Length, because VB array declarations use an inclusive upper bound rather than a count.
Related documentation¶
- Operations and processes
- Overview
- Architecture
- Dependencies
- Business rules
- Configuration
- API reference
Sources¶
- SAIF.Framework.Mail\MailServices.vb