@adviser/cement - v0.0.0
    Preparing search index...

    Function stream2string

    • Converts a ReadableStream of Uint8Array chunks to a string.

      Reads the entire stream (or up to maxSize bytes) and decodes it as UTF-8 text. Useful for consuming response bodies, file streams, etc.

      Parameters

      • Optionalstream: ReadableStream<Uint8Array<ArrayBufferLike>> | null

        The ReadableStream to convert (returns empty string if null/undefined)

      • OptionalmaxSize: number

        Optional maximum bytes to read before stopping

      Returns Promise<string>

      Promise resolving to the decoded string

      const response = await fetch('/api/data');
      const text = await stream2string(response.body);
      console.log(text);

      // With size limit
      const preview = await stream2string(response.body, 1000); // First 1KB