0.2.2 • Published 4 years ago
fs-read-stream-over-http v0.2.2
fs-read-stream-over-http
Deprecated in favor of stream-http
.
Isomorphic fs.createReadStream
. Delegates to core fs
in Node, uses the Browserify http
shim in the browser.
Installing
npm install fs-read-stream-over-http
Usage
You need to provide a function that maps local paths such as ./foo/bar.txt
to a URL:
const path = require('path')
const pathToUrl = local => 'https://example.org' + path.resolve('/', local)
It will be used in the browser, to fetch the file over HTTP. In Node, the local path will be used.
const fsCreateReadStream = require('fs-read-stream-over-http')
fsCreateReadStream('/foo/bar.txt', pathToUrl, {encoding: 'utf8'})
.on('data', console.log)
.once('end', () => console.log('end!'))
fsCreateReadStream
will throw when called with options that can't be fulfilled in the browser (e.g. flags
). Otherwise it will return a stream of decoded data.
Contributing
If you have a question or have difficulties using fs-read-stream-over-http
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.