Comparing version 3.0.0 to 3.0.1
@@ -15,2 +15,12 @@ 'use strict'; | ||
internals.Range = class { | ||
constructor(from, to) { | ||
this.from = from; | ||
this.to = to; | ||
} | ||
}; | ||
exports.header = function (header, length) { | ||
@@ -40,14 +50,15 @@ | ||
const set = {}; | ||
let from; | ||
let to; | ||
range = range.split('-'); | ||
if (range[0]) { | ||
set.from = parseInt(range[0], 10); | ||
from = parseInt(range[0], 10); | ||
} | ||
if (range[1]) { | ||
set.to = parseInt(range[1], 10); | ||
if (set.from !== undefined) { // Can be 0 | ||
to = parseInt(range[1], 10); | ||
if (from !== undefined) { // Can be 0 | ||
// From-To | ||
if (set.to > lastPos) { | ||
set.to = lastPos; | ||
if (to > lastPos) { | ||
to = lastPos; | ||
} | ||
@@ -57,4 +68,4 @@ } | ||
// -To | ||
set.from = length - set.to; | ||
set.to = lastPos; | ||
from = length - to; | ||
to = lastPos; | ||
} | ||
@@ -64,10 +75,10 @@ } | ||
// From- | ||
set.to = lastPos; | ||
to = lastPos; | ||
} | ||
if (set.from > set.to) { | ||
if (from > to) { | ||
return null; | ||
} | ||
result.push(set); | ||
result.push(new internals.Range(from, to)); | ||
} | ||
@@ -101,33 +112,60 @@ | ||
exports.Stream = internals.Stream = function (range) { | ||
exports.Stream = internals.Stream = class extends Stream.Transform { | ||
Stream.Transform.call(this); | ||
constructor(range) { | ||
this._range = range; | ||
this._next = 0; | ||
}; | ||
if (!(range instanceof internals.Range)) { | ||
Hoek.assert(typeof range === 'object', 'Expected "range" object'); | ||
Hoek.inherits(internals.Stream, Stream.Transform); | ||
const from = range.from || 0; | ||
Hoek.assert(typeof from === 'number', '"range.from" must be falsy, or a number'); | ||
Hoek.assert(from === parseInt(from, 10) && from >= 0, '"range.from" must be a positive integer'); | ||
const to = range.to || 0; | ||
Hoek.assert(typeof to === 'number', '"range.to" must be falsy, or a number'); | ||
Hoek.assert(to === parseInt(to, 10) && to >= 0, '"range.to" must be a positive integer'); | ||
internals.Stream.prototype._transform = function (chunk, encoding, done) { | ||
Hoek.assert(to >= from, '"range.to" must be greater than or equal to "range.from"'); | ||
// Read desired range from a stream | ||
range = new internals.Range(from, to); | ||
} | ||
const pos = this._next; | ||
this._next = this._next + chunk.length; | ||
super(); | ||
if (this._next <= this._range.from || // Before range | ||
pos > this._range.to) { // After range | ||
this._range = range; | ||
this._next = 0; | ||
} | ||
return done(); | ||
processChunk(chunk) { | ||
// Read desired range from a stream | ||
const pos = this._next; | ||
this._next = this._next + chunk.length; | ||
if (this._next <= this._range.from || // Before range | ||
pos > this._range.to) { // After range | ||
return; | ||
} | ||
// Calc bounds of chunk to read | ||
const from = Math.max(0, this._range.from - pos); | ||
const to = Math.min(chunk.length, this._range.to - pos + 1); | ||
this.push(chunk.slice(from, to)); | ||
} | ||
// Calc bounds of chunk to read | ||
_transform(chunk, encoding, done) { | ||
const from = Math.max(0, this._range.from - pos); | ||
const to = Math.min(chunk.length, this._range.to - pos + 1); | ||
try { | ||
this.processChunk(chunk); | ||
} | ||
catch (err) { | ||
return done(err); | ||
} | ||
this.push(chunk.slice(from, to)); | ||
return done(); | ||
return done(); | ||
} | ||
}; |
{ | ||
"name": "ammo", | ||
"description": "HTTP Range processing utilities", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"repository": "git://github.com/hapijs/ammo", | ||
@@ -13,6 +13,5 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=8.9.0" | ||
}, | ||
"dependencies": { | ||
"boom": "6.x.x", | ||
"hoek": "5.x.x" | ||
@@ -22,4 +21,4 @@ }, | ||
"code": "5.x.x", | ||
"lab": "14.x.x", | ||
"wreck": "13.x.x" | ||
"lab": "15.x.x", | ||
"wreck": "14.x.x" | ||
}, | ||
@@ -26,0 +25,0 @@ "scripts": { |
@@ -24,6 +24,5 @@ # ammo | ||
const stream = new Ammo.Stream(range[0]); | ||
Wreck.read(source.pipe(stream), {}, (err, buffer) => { | ||
// buffer is the portion of source within range | ||
const buffer = async Wreck.read(source.pipe(stream)); | ||
}); | ||
// buffer is the portion of source within range | ||
``` | ||
@@ -30,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7709
1
116
53
1
- Removedboom@6.x.x
- Removedboom@6.0.0(transitive)