Skip to main content
Version: v0.0.4

Type Alias: Hl7StreamSource

Hl7StreamSource = AsyncIterable<string | Buffer | Uint8Array> | Iterable<string | Buffer | Uint8Array>

A chunked source parseStream can consume: a Node Readable, any async-iterable, or any plain iterable of chunks. Chunks are string (text stream) or Buffer/Uint8Array (binary stream). A real Node stream in binary mode yields Buffers; in text mode it yields strings: a source is expected to be homogeneous (all-text or all-binary), which every real Readable is. A binary chunk is decoded 1:1 via latin1 (a lossless byte↔codepoint mapping) so each message's own MSH-18 charset resolution runs on its original bytes, exactly as splitBatch does.

Example

import { createReadStream } from "node:fs";
import { parseStream } from "@cosyte/hl7";

const src: Hl7StreamSource = createReadStream("feed.hl7");
for await (const entry of parseStream(src)) {
if (entry.ok) handle(entry.message);
else quarantine(entry.raw, entry.error.code);
}