process-stream-char-by-char

1.0.3 • Public • Published

Process Stream Char by Char

Improve the user experience "the ChatGPT way" by incrementally displaying data as it is streamed in.

This utility exposes two methods:

  1. stringToReadableStream: Transform a string to ReadableStream type.

    Usage: Convert a string to ReadableStream instance.

    import { stringToReadableStream } from 'process-stream-char-by-char'
    // ...
    const inputStream = stringToReadableStream(inputString)
  2. processStreamCharbyChar: If given an input stream of type ReadableStream and a callback function, the method decodes the string and calls the callback function for each decoded character. The decoded character will be passed as an argument to the callback

    Usage: Progressively add data to your react state as it is streamed in.

    import { processStreamCharbyChar } from 'process-stream-char-by-char'
     //...
     processStreamCharbyChar(inputStream, (char) => setState((prev) => prev + char))

Package Sidebar

Install

npm i process-stream-char-by-char

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

4.51 kB

Total Files

4

Last publish

Collaborators

  • ravish.goel