Giter VIP home page Giter VIP logo

ammo's Introduction

ammo

HTTP Range processing utilities.

Npm Version Build Status

Lead Maintainer - Gil Pedersen

Usage

// 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 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.

ammo's People

Contributors

arb avatar cjihrig avatar genediazjr avatar hargasinski avatar hueniverse avatar kanongil avatar

Watchers

 avatar  avatar

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.