Giter VIP home page Giter VIP logo

header-range-parser's Introduction

Header • Range • Parser

Header • Range • Parser

Range header field parser. Fork of a̶b̶a̶n̶d̶o̶n̶e̶d̶ range-parser. If you write to me with a request to change or update something, I will do it. Honestly 👼.

NPM Version NPM Downloads GitHub Stars Node.js Version TypeScript Typings

GitHub Checks Travis CI Snyk

Maintainability Rating LGTM Codacy Badge CodeFactor

Installation

npm install header-range-parser

API

const {
  ERROR_INVALID_ARGUMENT,
  ERROR_STRING_IS_NOT_HEADER,
  ERROR_UNSATISFIABLE_RESULT,
  parseRange,
} = require("header-range-parser");
import {
  ERROR_INVALID_ARGUMENT,
  ERROR_STRING_IS_NOT_HEADER,
  ERROR_UNSATISFIABLE_RESULT,
  ResultInvalid,
  ResultUnsatisfiable,
  ResultWrongArgument,
  parseRange,
} from "header-range-parser";

parseRange(size, header, options)

import {
  Result, Ranges, parseRange, Options,
} from "header-range-parser";

declare function parseRange(
  size: number, header: string, options?: Options,
): Ranges | Result;
Parameter Type Description
size number Required. Size in bytes.
header string Required. String containing header.
options object Optional options: combine (bool), throwError (bool).

Parse the given header string where size is the size of the selected representation that is to be partitioned into sub-ranges. An array of sub-ranges will be returned or negative numbers indicating an error parsing.

  • -1 or ERROR_UNSATISFIABLE_RESULT or esultUnsatisfiable signals an unsatisfiable range

  • -2 or ERROR_STRING_IS_NOT_HEADER or ResultInvalid signals a malformed header string

  • -3 or ERROR_INVALID_ARGUMENT or ResultWrongArgument invalid parameters

// parse header from request
const subRanges = parseRange(
  size,
  request.headers.range,
);

// the type of the subranges
if (subRanges.type === "bytes") {
  // the ranges
  subRanges.forEach((range) => {
    // do something
    // with range.start
    // and range.end
  });
}

Options

These properties are accepted in the options object.

combine

Specifies if overlapping and adjacent sub-ranges should be combined, defaults to false.

When true, ranges will be combined and returned as if they were specified that way in the header.

throwError

Throw or suppress errors. Defaults to true.

parseRange(
  100,
  "bytes=50-55,0-10,5-10,56-60",
  {
    combine: true,
    throwError: false,
  });
//  [
//    { start: 0,  end: 10 },
//    { start: 50, end: 60 }
//  ]

See also

💾 My other projects

Open Source

header-range-parser's People

Contributors

dependabot[bot] avatar r37r0m0d3l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

nitn3lav

header-range-parser's Issues

Empty dir on 1.1.2 version

Got no dist folder in node_modules/header-range-parser after installing 1.1.2 version

installing 1.1.1 fixes problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.