{"library":"node-web-stream-adapters","title":"Node.js Web Stream Adapters","description":"This package provides utilities to convert Node.js `Readable` and `Writable` streams into Web `ReadableStream` and `WritableStream` objects, and vice-versa. It aims to bridge the gap between Node.js's native stream API and the WHATWG Web Streams API, offering stable conversion functions. This is particularly useful because Node.js's own `Readable.toWeb`, `Writable.toWeb`, `Readable.fromWeb`, and `Writable.fromWeb` methods are marked as experimental as of Node.js version 22. The package is currently at version 0.2.1, indicating an early development stage, though it addresses a stable need. It is likely maintained as needed to keep pace with Node.js and Web Streams API evolutions. Key differentiators include providing a non-experimental, stable API surface for stream conversion.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-web-stream-adapters"],"cli":null},"imports":["import { toReadableStream } from 'node-web-stream-adapters';","import { createReadableStreamFromReadable } from 'node-web-stream-adapters';","import { createReadableStreamFromBuffer } from 'node-web-stream-adapters';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import fs from \"fs/promises\";\nimport { createReadableStreamFromBuffer } from \"node-web-stream-adapters\";\n\nasync function processFileAsStream() {\n  try {\n    const filePath = 'some-file.txt';\n    // Assume 'some-file.txt' exists and has content.\n    // In a real scenario, you might read a large file or network response.\n    const buffer = await fs.readFile(filePath);\n    const webStream = createReadableStreamFromBuffer(buffer);\n\n    console.log('Created Web ReadableStream from buffer.');\n\n    // Example: Consume the web stream (e.g., pipe to another writable stream or process chunks)\n    const reader = webStream.getReader();\n    while (true) {\n      const { done, value } = await reader.read();\n      if (done) {\n        console.log('Stream finished.');\n        break;\n      }\n      console.log('Received chunk:', new TextDecoder().decode(value));\n    }\n  } catch (error) {\n    console.error('Error processing stream:', error);\n  }\n}\n\n// Create a dummy file for the example to run\nasync function setupDummyFile() {\n  const content = 'Hello, Web Streams!\\nThis is a test file.';\n  await fs.writeFile('some-file.txt', content);\n  console.log('Dummy file created: some-file.txt');\n  await processFileAsStream();\n}\n\nsetupDummyFile();","lang":"typescript","description":"This example demonstrates how to convert a Node.js Buffer into a Web ReadableStream using `createReadableStreamFromBuffer` and then consume it.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}