process-stream-char-by-char
v1.0.3
Published
A utility that process a ReadableStream instance character by character.
Maintainers
Readme
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:
stringToReadableStream: Transform a string toReadableStreamtype.Usage: Convert a string to
ReadableStreaminstance.import { stringToReadableStream } from 'process-stream-char-by-char' // ... const inputStream = stringToReadableStream(inputString)processStreamCharbyChar: If given an input stream of typeReadableStreamand 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 callbackUsage: 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))
