jsonl-webstream
Lightweight library for JSON Lines web stream between browsers and Node.js environments
Overview
This library provides utilities for processing JSON Lines formatted data through the Web Streams API It enables efficient streaming of JSON Lines data with minimal memory overhead across browsers and Node.js environments.
Installation
npm install jsonl-webstream
Usage
Reading JSON Lines
import { createJsonLinesReceiver } from 'jsonl-webstream';
// With fetch API
async function processJsonLines() {
const response = await fetch('https://example.com/stream');
const reader = response.body.getReader();
const jsonlStream = createJsonLinesReceiver(reader);
for await (const jsonData of jsonlStream) {
// Process each JSON object
console.log(jsonData);
}
}
Writing JSON Lines
import { createJsonLinesSender } from 'jsonl-webstream';
function handleRequest(reply) {
// Create a JSON Lines writer and its associated stream
const {…