https://github.com/131/random-read-http
Continuous reading from a http(s) url using random offsets and lengths
https://github.com/131/random-read-http
Last synced: 10 months ago
JSON representation
Continuous reading from a http(s) url using random offsets and lengths
- Host: GitHub
- URL: https://github.com/131/random-read-http
- Owner: 131
- License: mit
- Created: 2019-07-27T09:57:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T14:53:20.000Z (about 4 years ago)
- Last Synced: 2025-07-26T16:24:09.584Z (11 months ago)
- Language: JavaScript
- Size: 867 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/131/random-read-http/actions/workflows/test.yml)
[](https://coveralls.io/github/131/random-read-http?branch=master)
[](https://www.npmjs.com/package/random-read-http)
[](http://opensource.org/licenses/MIT)
[](https://www.npmjs.com/package/eslint-plugin-ivs)
# Motivation
This module allows you to open an http(s) url and read through it at random offsets (seeking). This is usefull when working with pseudo-fs like [cloudfs](https://github.com/131/cloudfs).
It's optimized for speed and efficiency, using http(s) agent & http 1.1 polling & a read-ahead buffer list to control the flow and minimize round-trips.
# API / usage
```
const RandomReadHTTP = require('random-read-http');
let remote = new RandomReadHTTP("https://someurl/somefile.mkv");
remote.read(buf, 0, 10, function(len) {
console.log("Got 10 first bytes into", buf);
remote.close(); //free up http agent
});
```
## constructor(remote_url [, options])
Options are :
* **MAX_BL_SIZE** (default to 20MB). flow will be paused when internal buffer reach **MAX_BL_SIZE** limit.
* **MIN_BL_SIZE** (default to 2.5MB). flow will be resumed if internal buffer is lower than **MIN_BL_SIZE**.
# Credits / inspiration
* [131](https://github.com/131)
* [Nick Craig-Wood' rclone/vfs/read/doSeek](https://github.com/ncw/rclone/blob/master/vfs/read.go#L217)
* [mafintosh' random-access-stuffs](https://github.com/random-access-storage)