1b2437590aa09837190b4974f4a5fc934198f56f
[aai/esr-gui.git] /
1 # range-parser
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
8
9 Range header field parser.
10
11 ## Installation
12
13 ```
14 $ npm install range-parser
15 ```
16
17 ## API
18
19 ```js
20 var parseRange = require('range-parser')
21 ```
22
23 ### parseRange(size, header, options)
24
25 Parse the given `header` string where `size` is the maximum size of the resource.
26 An array of ranges will be returned or negative numbers indicating an error parsing.
27
28   * `-2` signals a malformed header string
29   * `-1` signals an unsatisfiable range
30
31 ```js
32 // parse header from request
33 var range = parseRange(size, req.headers.range)
34
35 // the type of the range
36 if (range.type === 'bytes') {
37   // the ranges
38   range.forEach(function (r) {
39     // do something with r.start and r.end
40   })
41 }
42 ```
43
44 #### Options
45
46 These properties are accepted in the options object.
47
48 ##### combine
49
50 Specifies if overlapping & adjacent ranges should be combined, defaults to `false`.
51 When `true`, ranges will be combined and returned as if they were specified that
52 way in the header.
53
54 ```js
55 parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
56 // => [
57 //      { start: 0,  end: 10 },
58 //      { start: 50, end: 60 }
59 //    ]
60 ```
61
62 ## License
63
64 [MIT](LICENSE)
65
66 [npm-image]: https://img.shields.io/npm/v/range-parser.svg
67 [npm-url]: https://npmjs.org/package/range-parser
68 [node-version-image]: https://img.shields.io/node/v/range-parser.svg
69 [node-version-url]: https://nodejs.org/endownload
70 [travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg
71 [travis-url]: https://travis-ci.org/jshttp/range-parser
72 [coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg
73 [coveralls-url]: https://coveralls.io/r/jshttp/range-parser
74 [downloads-image]: https://img.shields.io/npm/dm/range-parser.svg
75 [downloads-url]: https://npmjs.org/package/range-parser