Comparing version 1.0.1 to 2.0.0
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Stream = require('stream'); | ||
var Hoek = require('hoek'); | ||
const Stream = require('stream'); | ||
const Hoek = require('hoek'); | ||
@@ -9,3 +11,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -17,3 +19,3 @@ | ||
var parts = header.split('='); | ||
const parts = header.split('='); | ||
if (parts.length !== 2 || | ||
@@ -25,8 +27,8 @@ parts[0] !== 'bytes') { | ||
var lastPos = length - 1; | ||
const lastPos = length - 1; | ||
var result = []; | ||
var ranges = parts[1].match(/\d*\-\d*/g); | ||
for (var i = 0, il = ranges.length; i < il; ++i) { | ||
var range = ranges[i]; | ||
const result = []; | ||
const ranges = parts[1].match(/\d*\-\d*/g); | ||
for (let i = 0; i < ranges.length; ++i) { | ||
let range = ranges[i]; | ||
if (range.length === 1) { // '-' | ||
@@ -36,3 +38,3 @@ return null; | ||
var set = {}; | ||
const set = {}; | ||
range = range.split('-'); | ||
@@ -75,11 +77,8 @@ if (range[0]) { | ||
result.sort(function (a, b) { | ||
result.sort((a, b) => a.from - b.from); | ||
return a.from - b.from; | ||
}); | ||
var consolidated = []; | ||
for (i = result.length - 1; i > 0; --i) { | ||
var current = result[i]; | ||
var before = result[i - 1]; | ||
const consolidated = []; | ||
for (let i = result.length - 1; i > 0; --i) { | ||
const current = result[i]; | ||
const before = result[i - 1]; | ||
if (current.from <= before.to + 1) { | ||
@@ -112,4 +111,4 @@ before.to = current.to; | ||
var pos = this._next; | ||
this._next += chunk.length; | ||
const pos = this._next; | ||
this._next = this._next + chunk.length; | ||
@@ -122,4 +121,4 @@ if (this._next <= this._range.from || // Before range | ||
var from = Math.max(0, this._range.from - pos); | ||
var to = Math.min(chunk.length, this._range.to - pos + 1); | ||
const from = Math.max(0, this._range.from - pos); | ||
const to = Math.min(chunk.length, this._range.to - pos + 1); | ||
@@ -126,0 +125,0 @@ this.push(chunk.slice(from, to)); |
{ | ||
"name": "ammo", | ||
"description": "HTTP Range processing utilities", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"repository": "git://github.com/hapijs/ammo", | ||
@@ -13,12 +13,12 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.32" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"boom": "2.x.x", | ||
"hoek": "2.x.x" | ||
"boom": "3.x.x", | ||
"hoek": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"code": "1.x.x", | ||
"lab": "5.x.x", | ||
"wreck": "5.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x", | ||
"wreck": "7.x.x" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
@@ -0,9 +1,11 @@ | ||
'use strict'; | ||
// Load modules | ||
var Stream = require('stream'); | ||
var Ammo = require('..'); | ||
var Code = require('code'); | ||
var Hoek = require('hoek'); | ||
var Lab = require('lab'); | ||
var Wreck = require('wreck'); | ||
const Stream = require('stream'); | ||
const Ammo = require('..'); | ||
const Code = require('code'); | ||
const Hoek = require('hoek'); | ||
const Lab = require('lab'); | ||
const Wreck = require('wreck'); | ||
@@ -13,3 +15,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -19,11 +21,11 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('header()', function () { | ||
describe('header()', () => { | ||
it('parses header (start)', function (done) { | ||
it('parses header (start)', (done) => { | ||
@@ -34,3 +36,3 @@ expect(Ammo.header('bytes=0-4', 10)).to.deep.equal([{ from: 0, to: 4 }]); | ||
it('parses header (middle)', function (done) { | ||
it('parses header (middle)', (done) => { | ||
@@ -41,3 +43,3 @@ expect(Ammo.header('bytes=1-5', 10)).to.deep.equal([{ from: 1, to: 5 }]); | ||
it('parses header (-to)', function (done) { | ||
it('parses header (-to)', (done) => { | ||
@@ -48,3 +50,3 @@ expect(Ammo.header('bytes=-5', 10)).to.deep.equal([{ from: 5, to: 9 }]); | ||
it('parses header (from-)', function (done) { | ||
it('parses header (from-)', (done) => { | ||
@@ -55,3 +57,3 @@ expect(Ammo.header('bytes=5-', 45000)).to.deep.equal([{ from: 5, to: 44999 }]); | ||
it('parses header (beyond end)', function (done) { | ||
it('parses header (beyond end)', (done) => { | ||
@@ -62,3 +64,3 @@ expect(Ammo.header('bytes=10-20', 15)).to.deep.equal([{ from: 10, to: 14 }]); | ||
it('parses header (wrong unit)', function (done) { | ||
it('parses header (wrong unit)', (done) => { | ||
@@ -69,3 +71,3 @@ expect(Ammo.header('horses=1-5', 10)).to.equal(null); | ||
it('parses header (flipped)', function (done) { | ||
it('parses header (flipped)', (done) => { | ||
@@ -76,3 +78,3 @@ expect(Ammo.header('bytes=5-1', 10)).to.equal(null); | ||
it('parses header (missing =)', function (done) { | ||
it('parses header (missing =)', (done) => { | ||
@@ -83,3 +85,3 @@ expect(Ammo.header('bytes 1-5', 10)).to.equal(null); | ||
it('parses header (missing to and from)', function (done) { | ||
it('parses header (missing to and from)', (done) => { | ||
@@ -90,3 +92,3 @@ expect(Ammo.header('bytes=-', 10)).to.equal(null); | ||
it('parses header (multiple ranges)', function (done) { | ||
it('parses header (multiple ranges)', (done) => { | ||
@@ -97,3 +99,3 @@ expect(Ammo.header('bytes=1-5,7-10', 10)).to.deep.equal([{ from: 1, to: 5 }, { from: 7, to: 9 }]); | ||
it('parses header (overlapping ranges)', function (done) { | ||
it('parses header (overlapping ranges)', (done) => { | ||
@@ -105,12 +107,12 @@ expect(Ammo.header('bytes=1-5,5-10', 10)).to.deep.equal([{ from: 1, to: 9 }]); | ||
describe('Stream', function () { | ||
describe('Stream', () => { | ||
it('returns a subset of a stream', function (done) { | ||
it('returns a subset of a stream', (done) => { | ||
var random = new Buffer(5000); | ||
var source = Wreck.toReadableStream(random); | ||
var range = Ammo.header('bytes=1000-4000', 5000); | ||
var stream = new Ammo.Stream(range[0]); | ||
const random = new Buffer(5000); | ||
const source = Wreck.toReadableStream(random); | ||
const range = Ammo.header('bytes=1000-4000', 5000); | ||
const stream = new Ammo.Stream(range[0]); | ||
Wreck.read(source.pipe(stream), {}, function (err, buffer) { | ||
Wreck.read(source.pipe(stream), {}, (err, buffer) => { | ||
@@ -122,5 +124,5 @@ expect(buffer.toString()).to.equal(random.slice(1000, 4001).toString()); | ||
it('processes multiple chunks', function (done) { | ||
it('processes multiple chunks', (done) => { | ||
var TestStream = function () { | ||
const TestStream = function () { | ||
@@ -149,7 +151,7 @@ Stream.Readable.call(this); | ||
var range = Ammo.header('bytes=2-4', 10); | ||
var stream = new Ammo.Stream(range[0]); | ||
const range = Ammo.header('bytes=2-4', 10); | ||
const stream = new Ammo.Stream(range[0]); | ||
var source = new TestStream(); | ||
Wreck.read(source.pipe(stream), {}, function (err, buffer) { | ||
const source = new TestStream(); | ||
Wreck.read(source.pipe(stream), {}, (err, buffer) => { | ||
@@ -156,0 +158,0 @@ expect(buffer.toString()).to.equal('234'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9720
+ Addedboom@3.2.2(transitive)
+ Addedhoek@3.0.44.3.1(transitive)
- Removedboom@2.10.1(transitive)
- Removedhoek@2.16.3(transitive)
Updatedboom@3.x.x
Updatedhoek@3.x.x