Grounds
    Preparing search index...

    Function createEncoderStream

    • Creates a TransformStream for encoding Relish values to bytes.

      Implements the Web Streams API for use with ReadableStream/WritableStream. Compatible with browser and Node.js 18+ environments.

      Returns TransformStream<RelishValue, Uint8Array<ArrayBufferLike>>

      TransformStream<RelishValue, Uint8Array>

      Piping with Web Streams:

      import { createEncoderStream } from '@grounds/stream';
      import { U32 } from '@grounds/core';

      const encoder = createEncoderStream();

      const readable = new ReadableStream({
      async start(controller) {
      controller.enqueue(U32(1));
      controller.enqueue(U32(2));
      controller.close();
      }
      });

      const bytesStream = readable.pipeThrough(encoder);

      for await (const bytes of bytesStream) {
      console.log('Encoded chunk:', bytes.length, 'bytes');
      }

      Encoding errors are not thrown - check the stream output for Error Results. For error handling, use the async generator API (encodeIterable) which yields Result types.