You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

7 years ago
  1. # range-parser
  2. [![NPM Version][npm-image]][npm-url]
  3. [![NPM Downloads][downloads-image]][downloads-url]
  4. [![Node.js Version][node-version-image]][node-version-url]
  5. [![Build Status][travis-image]][travis-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. Range header field parser.
  8. ## Installation
  9. ```
  10. $ npm install range-parser
  11. ```
  12. ## API
  13. ```js
  14. var parseRange = require('range-parser')
  15. ```
  16. ### parseRange(size, header)
  17. Parse the given `header` string where `size` is the maximum size of the resource.
  18. An array of ranges will be returned or negative numbers indicating an error parsing.
  19. * `-2` signals a malformed header string
  20. * `-1` signals an invalid range
  21. ```js
  22. // parse header from request
  23. var range = parseRange(req.headers.range)
  24. // the type of the range
  25. if (range.type === 'bytes') {
  26. // the ranges
  27. range.forEach(function (r) {
  28. // do something with r.start and r.end
  29. })
  30. }
  31. ```
  32. ## License
  33. [MIT](LICENSE)
  34. [npm-image]: https://img.shields.io/npm/v/range-parser.svg
  35. [npm-url]: https://npmjs.org/package/range-parser
  36. [node-version-image]: https://img.shields.io/node/v/range-parser.svg
  37. [node-version-url]: http://nodejs.org/download/
  38. [travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg
  39. [travis-url]: https://travis-ci.org/jshttp/range-parser
  40. [coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg
  41. [coveralls-url]: https://coveralls.io/r/jshttp/range-parser
  42. [downloads-image]: https://img.shields.io/npm/dm/range-parser.svg
  43. [downloads-url]: https://npmjs.org/package/range-parser