Streaming utilities for encoding and decoding Relish values incrementally.
Provides both async generator and Web Streams API support for streaming scenarios. Includes schema-aware streaming for type-safe operations.
Async generator streaming:
import { encodeIterable, decodeIterable } from '@grounds/stream';import { U32 } from '@grounds/core';async function* generateValues() { yield U32(1); yield U32(2);}// Encodefor await (const result of encodeIterable(generateValues())) { // Process encoded bytes}// Decodeasync function* readChunks() { // Read from network, file, etc.}for await (const result of decodeIterable(readChunks())) { // Process decoded values} Copy
import { encodeIterable, decodeIterable } from '@grounds/stream';import { U32 } from '@grounds/core';async function* generateValues() { yield U32(1); yield U32(2);}// Encodefor await (const result of encodeIterable(generateValues())) { // Process encoded bytes}// Decodeasync function* readChunks() { // Read from network, file, etc.}for await (const result of decodeIterable(readChunks())) { // Process decoded values}
Web Streams API:
import { createEncoderStream, createDecoderStream } from '@grounds/stream';const encoder = createEncoderStream();const decoder = createDecoderStream();valuesStream.pipeThrough(encoder).pipeThrough(decoder); Copy
import { createEncoderStream, createDecoderStream } from '@grounds/stream';const encoder = createEncoderStream();const decoder = createDecoderStream();valuesStream.pipeThrough(encoder).pipeThrough(decoder);
Schema-aware streaming with async generators:
import { encodeIterable } from '@grounds/stream';import { createCodec, RStruct, field, RString, type Static } from '@grounds/schema';const schema = RStruct({ name: field(0, RString()) });type Data = Static<typeof schema>;async function* generate(): AsyncGenerator<Data> { yield { name: 'Alice' };}const codec = createCodec(schema);for await (const result of encodeIterable(generate())) { result.match( (bytes) => console.log('Encoded:', bytes), (error) => console.error('Failed:', error) );} Copy
import { encodeIterable } from '@grounds/stream';import { createCodec, RStruct, field, RString, type Static } from '@grounds/schema';const schema = RStruct({ name: field(0, RString()) });type Data = Static<typeof schema>;async function* generate(): AsyncGenerator<Data> { yield { name: 'Alice' };}const codec = createCodec(schema);for await (const result of encodeIterable(generate())) { result.match( (bytes) => console.log('Encoded:', bytes), (error) => console.error('Failed:', error) );}
Two API styles:
Schema-aware variants combine validation from @grounds/schema with streaming.
@grounds/schema
Streaming utilities for encoding and decoding Relish values incrementally.
Provides both async generator and Web Streams API support for streaming scenarios. Includes schema-aware streaming for type-safe operations.
Example
Async generator streaming:
Example
Web Streams API:
Example
Schema-aware streaming with async generators:
Remarks
Two API styles:
Schema-aware variants combine validation from
@grounds/schemawith streaming.See