# sharef

> Quickly share a file over HTTP

Latest version **1.1.0** (published 2018-09-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install sharef
pnpm add sharef
yarn add sharef
bun add sharef
```

Provides the command `sharef`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-09-13 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 20 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | Joseph Werle |
| Maintainers | werle |
| Keywords | http, share, quick |

## Links

- npm: https://www.npmjs.com/package/sharef
- npm.io page: https://npm.io/package/sharef

## Dependencies (20)

- [got](https://npm.io/package/got.md) ^9.1.0
- [mime](https://npm.io/package/mime.md) ^2.3.1
- [pump](https://npm.io/package/pump.md) ^3.0.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [yargs](https://npm.io/package/yargs.md) ^12.0.1
- [corsify](https://npm.io/package/corsify.md) ^2.1.0
- [hypercore](https://npm.io/package/hypercore.md) ^6.18.2
- [hyperdrive](https://npm.io/package/hyperdrive.md) ^9.14.0
- [internal-ip](https://npm.io/package/internal-ip.md) ^3.0.1
- [randombytes](https://npm.io/package/randombytes.md) ^2.0.6
- [range-parser](https://npm.io/package/range-parser.md) ^1.2.0
- [hyperdiscovery](https://npm.io/package/hyperdiscovery.md) ^8.0.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^2.3.0
- [async-exit-hook](https://npm.io/package/async-exit-hook.md) ^2.0.1
- [hyperdrive-http](https://npm.io/package/hyperdrive-http.md) ^4.3.3
- [random-access-file](https://npm.io/package/random-access-file.md) ^2.0.1
- [random-access-http](https://npm.io/package/random-access-http.md) ^2.0.1
- [random-access-memory](https://npm.io/package/random-access-memory.md) ^3.0.0
- [random-access-stream](https://npm.io/package/random-access-stream.md) ^2.0.0

## Recent versions

- 1.1.0 (latest) — 2018-09-13
- 1.0.0 — 2018-09-13
- 0.2.1 — 2018-08-27
- 0.2.0 — 2018-08-27
- 0.1.1 — 2018-08-23

## README

sharef
======

Quickly share a file over HTTP, DAT, and Hypercore.

## Installation

```sh
$ npm install sharef
```

## Usage

`sharef` can be used as a module or from the command line. `sharef` is a
function that accepts a
[random-access-storage](https://github.com/random-access-storage/random-access-storage)
interface or a string that resolves to
[random-access-http](https://github.com/random-access-storage/random-access-http) or
[random-access-file](https://github.com/random-access-storage/random-access-file).

### Command Line

`sharef` describes the following command line usage.

```sh
usage: sharef [-hDV] [options] <pathspec>

Options:
  -h, --help     Show help                          [boolean]
  -V, --version  Show version number                [boolean]
  -D, --debug    Enable debug output                [boolean] [default: false]
  -p, --port     Port for HTTP server to listen on  [number] [default: 8000]
  -m, --max      Max shares before exiting          [number] [default: Infinity]
```

## Example

The following example will read a file from github using a ranged
request. The request is made to the `sharef` server and accessed using a
[random-access-http](https://github.com/random-access-storage/random-access-http).
When a share has occurred, the server wil close itself.

```js
const fetch = require('got')
const share = require('sharef')

const file = 'https://raw.githubusercontent.com/datproject/hyperdrive-http/master/index.js'
const port = 8000

const server = share(file, { port })

server.once('share', onshare)
server.on('error', onerror)

void async function main() {
  const id = server.id.toString('hex')
  const res = await fetch(`http://localhost:${port}/${id}`, {
    headers: { range: 'bytes=0-100' }
  })

  console.log(res.body);
}()

async function onshare(info) {
  server.close()
}

function onerror(err) {
  console.error(err.stack || err)
}
```

This example can be recreated on the command line by invoking the
following command:

```sh
$ sharef https://raw.githubusercontent.com/datproject/hyperdrive-http/master/index.js
 info Sharing file: https://raw.githubusercontent.com/datproject/hyperdrive-http/master/index.js
 info Server Port: 8000
 info Server ID: /b0d4281e
 info Share IP: 192.168.128.111
 info Share URL: http://192.168.128.111:8000/b0d4281e
```

In another terminal you can request this file with `curl`.

```sh
$ curl http://192.168.128.111:8000/b0d4281e
```

## API

### `server = share(storage, opts)`

`share()` returns a
[http.Server](https://nodejs.org/api/http.html#http_class_http_server)
instances that responds to a single route

#### `server.id`

A random `4` byte buffer used to identify this route.

#### `server.route`

A `RegExp` instance created from [path-to-regexp](
https://github.com/pillarjs/path-to-regexp) that creates a unique route
from `server.id`

#### `server.on('share', info)`

Emitted each time a "share" occurs. That is a successful request and
response of the shared file.

## License

MIT

---
_Source: https://npm.io/package/sharef · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
