Registry / storage / path-source

path-source

JSON →
library0.1.3jsnpmunverified

Read files in Node.js or fetch URLs in browsers as standard WhatWG readable streams. Version 0.1.3 provides a unified API for streaming file I/O and HTTP responses. Designed for incremental data processing, it returns a ReadableStream reader with `read()` and `cancel()` methods. In Node, it wraps file streams; in browsers, it uses the Fetch API with streaming support when available, falling back to XMLHttpRequest. Lightweight and zero-dependency for the core feature, but requires `array-source` in older browsers. Part of a family of stream sources by Mike Bostock.

npm install path-source
INSTALL
IMPORT
SIG · PATH-SOURCE
P
path-source
storagejavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

path
import path from 'path-source'
import { path } from 'path-source'
Default export is a function; CommonJS: const path = require('path-source')

Reads a file as a stream and writes chunks to stdout. Demonstrates async iteration and proper cleanup.

import path from 'path-source'; import process from 'process'; path('README.md') .then(async (source) => { let result; while (!(result = await source.read()).done) { process.stdout.write(result.value); } }) .catch(err => console.error(err));
Debug
Known issues
gotchaIn browsers, path() returns a ReadableStream reader only if the browser supports streaming fetch. Otherwise it falls back to array-source which loads the entire resource into memory.
fix
Ensure array-source is loaded when using in older browsers (or use polyfills).
affects: >=0.0.0
gotchaThe stream reader's read() method returns an object with value as Uint8Array (or Buffer). In Node, value is a Buffer; in browsers, it is a Uint8Array.
fix
Treat value consistently as a Uint8Array; use TextDecoder if you need string output.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: path is not a function
Using named import instead of default import.
fix
Use `import path from 'path-source'` or `const path = require('path-source')`
Uncaught TypeError: source.read is not a function
Using the promise result incorrectly: may have chained improperly or used array-source directly.
fix
Ensure you are calling path() which returns a promise resolving to a source object with .read() method.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Amazon
1
Resources
path-source — npm install path-source · libregistry