# ammo

> HTTP Range processing utilities

Latest version **3.0.3** (published 2018-11-03) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2018-11-03 |
| First published | 2014-11-18 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 1 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | hueniverse, kanongil, marsup, nlf, wyatt |
| Keywords | http, range, utilities |

## Links

- npm: https://www.npmjs.com/package/ammo
- Repository: https://github.com/hapijs/ammo
- Homepage: https://github.com/hapijs/ammo#readme
- Issues: https://github.com/hapijs/ammo/issues
- npm.io page: https://npm.io/package/ammo

## Dependencies (1)

- [hoek](https://npm.io/package/hoek.md) 6.x.x

## Recent versions

- 3.0.3 (latest) — 2018-11-03
- 2.1.2 (v2-legacy) — 2024-01-01
- 3.0.2 — 2018-11-01
- 3.0.1 — 2018-04-26
- 3.0.0 — 2017-09-26
- 2.0.4 — 2017-05-28
- 2.0.3 — 2016-11-29
- 2.0.2 — 2016-07-27
- 2.0.1 — 2016-05-19
- 2.0.0 — 2015-11-01
- 1.0.1 — 2015-06-28
- 1.0.0 — 2014-11-18

## README

# ammo

HTTP Range processing utilities.

[![Npm Version](https://img.shields.io/npm/v/ammo.svg)](https://npmjs.com/package/ammo)
[![Build Status](https://secure.travis-ci.org/hapijs/ammo.png)](http://travis-ci.org/hapijs/ammo)

Lead Maintainer - [Gil Pedersen](https://github.com/kanongil)

## Usage

```js
// basic usage
const range = Ammo.header('bytes=1-5', 10);
// range --> [{ from: 1, to: 5 }]

// multiple ranges
const range = Ammo.header('bytes=1-5,7-10', 10);
// range --> [{ from: 1, to: 5 }, { from: 7, to: 9 }]

// streams (get range within a `source`)
const range = Ammo.header('bytes=1000-4000', 5000);
const stream = new Ammo.Stream(range[0]);
const buffer = async Wreck.read(source.pipe(stream));

// buffer is the portion of source within range
```

## API

### `header(header, length)`

Parses the range from a HTTP header.

* `header` - A string in the form of `bytes=from-to`, where `from` and `to` are
integers specifying the range. Both are optional. Multiple ranges can be passed
as a comma delimited list.
* `length` - A positive integer specifying the maximum length the range can
cover. If a `to` value passed in the `header` string is greater than `length`,
the `to` value is set as `length - 1`.

Returns an array of objects with the properties `from` and `to`, which specify
the beginning and ending of the range. Overlapping ranges are combined into one
object. Returns `null` for invalid input.

### `new Ammo.Stream(range)`

Creates a [`Transform Stream`](https://nodejs.org/api/stream.html) that extracts
the portion of a piped in stream within `range`.
* `range` - an object with the properties `from` and `to` that specify the range
of the piped in stream to read. Objects returned by `Ammo.header` can be passed
into `range`.

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