Socket
Socket
Sign inDemoInstall

range-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    range-parser

Range header field string parser


Version published
Weekly downloads
24M
decreased by-18.91%
Maintainers
1
Install size
3.38 kB
Created
Weekly downloads
 

Package description

What is range-parser?

The range-parser package is a utility for parsing HTTP range header fields. It's useful for handling requests for specific ranges of data, which is particularly relevant for serving large files in smaller chunks, such as videos or large documents.

What are range-parser's main functionalities?

Parse Range Header

This feature allows you to parse the 'Range' header from HTTP requests. It takes the size of the file and the range header as arguments and returns an array of ranges, or an error code if the range is unsatisfiable or syntactically invalid.

const rangeParser = require('range-parser');
const rangeHeader = 'bytes=0-499';
const fileSize = 1000;
const parsedRanges = rangeParser(fileSize, rangeHeader);

Other packages similar to range-parser

Readme

Source

node-range-parser

Range header field parser.

Example:

assert(-1 == parse(200, 'bytes=500-20'));
assert(-2 == parse(200, 'bytes=malformed'));
parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }]));
parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }]));
parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }]));
parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }]));
parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }]));
parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }]));
parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }]));
parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }]));
parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }]));

Installation

$ npm install range-parser

FAQs

Last updated on 18 Jun 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc