https://github.com/anderspitman/fibridge-host-js
https://github.com/anderspitman/fibridge-host-js
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/anderspitman/fibridge-host-js
- Owner: anderspitman
- License: mit
- Created: 2018-09-06T21:42:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-06T17:58:40.000Z (over 6 years ago)
- Last Synced: 2025-03-15T07:54:24.779Z (about 1 year ago)
- Language: JavaScript
- Size: 62.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The point of fibridge `(FIle BRIDGE)` is to allow your browser to "host" files
which can be streamed over HTTP. This requires a proxy server to handle the
HTTP requests and forward them to the browser over websockets. The proxy server
lives
[here](https://github.com/anderspitman/fibridge-proxy).
Why would this be useful? If the user has a very large file (genomic data files
can easily be in the 20GB-200GB range), and you want to make
[ranged requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests)
to that file (ie only download specific chunks) as though it were hosted on a
normal server, fibridge provides this functionality.
NOTE: This is an early work in progress and not quite ready to be used for
in production.
# Example usage
First install the proxy server. See [here](https://github.com/anderspitman/fibridge-proxy-rs).
A simple example is below. For a more complete implementation, see the source for
[fibridge-gui-js](https://github.com/anderspitman/fibridge-gui-js).
Create a Hoster object in the browser and host a couple files. See
`dist/index.html` for a working example where the user selects a file from
their computer.
```javascript
fibridge.createHoster({ proxyAddress: 'localhost', port: 8080, secure: false }).then((hoster) => {
const file1 = new File(["Hi there"], "file1.txt", {
type: "text/plain",
});
const file2 = new File(["I'm Old Gregg"], "file2.txt", {
type: "text/plain",
});
hoster.hostFile({ path: '/file1', file: file1 });
hoster.hostFile({ path: '/file2', file: file2 });
});
```
Retrieve the files using any http client:
```bash
curl localhost:8080/file1
Hi there
curl localhost:8080/file2
I'm Old Gregg
```
Ranged requests work too:
```bash
curl -H "Range: bytes=0-2" localhost:8080/file1
Hi
```