probe-image-size
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -0,1 +1,8 @@ | ||
2.1.0 / 2016-07-14 | ||
------------------ | ||
- Internal parsers api cleanup - switch from callbacks to events. | ||
- Fixed "write after end" error under heavy load. | ||
2.0.1 / 2016-07-01 | ||
@@ -2,0 +9,0 @@ ------------------ |
@@ -10,3 +10,3 @@ 'use strict'; | ||
function ParserStream() { | ||
Transform.call(this); | ||
Transform.call(this, { readableObjectMode: true }); | ||
} | ||
@@ -13,0 +13,0 @@ |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -14,4 +13,3 @@ var sliceEq = require('../common').sliceEq; | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -23,7 +21,7 @@ | ||
if (!sliceEq(data, 0, SIG_BM)) { | ||
callback(); | ||
parser.push(null); | ||
return; | ||
} | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt16LE(18), | ||
@@ -36,7 +34,9 @@ height: data.readUInt16LE(22), | ||
}); | ||
parser.push(null); | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -15,4 +14,3 @@ var sliceEq = require('../common').sliceEq; | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -23,8 +21,8 @@ | ||
if (!sliceEq(data, 0, SIG_GIF87a) && !sliceEq(data, 0, SIG_GIF89a)) { | ||
callback(); | ||
if (!sliceEq(data, 0, SIG_GIF87a) && !sliceEq(data, 0, SIG_GIF89a)) { | ||
parser.push(null); | ||
return; | ||
} | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt16LE(6), | ||
@@ -37,7 +35,9 @@ height: data.readUInt16LE(8), | ||
}); | ||
parser.push(null); | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
@@ -40,3 +39,3 @@ | ||
function getJpegSize(parser, callback) { | ||
function getJpegSize(parser) { | ||
parseJpegMarker(parser, function (code, length) { | ||
@@ -46,3 +45,3 @@ if (!code || length < 0) { | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -54,3 +53,3 @@ } | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -61,3 +60,3 @@ } | ||
// e.g. empty comment | ||
getJpegSize(parser, callback); | ||
getJpegSize(parser); | ||
return; | ||
@@ -72,3 +71,4 @@ } | ||
parser._skipBytes(Infinity); | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt16BE(3), | ||
@@ -81,2 +81,4 @@ height: data.readUInt16BE(1), | ||
}); | ||
parser.push(null); | ||
}); | ||
@@ -87,3 +89,3 @@ return; | ||
parser._skipBytes(length, function () { | ||
getJpegSize(parser, callback); | ||
getJpegSize(parser); | ||
}); | ||
@@ -94,4 +96,3 @@ }); | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -103,12 +104,12 @@ | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
} | ||
getJpegSize(parser, callback); | ||
getJpegSize(parser); | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -15,4 +14,3 @@ var sliceEq = require('../common').sliceEq; | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -25,3 +23,3 @@ | ||
if (!sliceEq(data, 0, SIG_PNG)) { | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -32,7 +30,7 @@ } | ||
if (!sliceEq(data, 12, SIG_IHDR)) { | ||
callback(); | ||
parser.push(null); | ||
return; | ||
} | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt32BE(16), | ||
@@ -45,7 +43,9 @@ height: data.readUInt32BE(20), | ||
}); | ||
parser.push(null); | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -14,4 +13,3 @@ var sliceEq = require('../common').sliceEq; | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -23,3 +21,3 @@ | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -30,3 +28,4 @@ } | ||
parser._skipBytes(Infinity); | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt32BE(12), | ||
@@ -39,8 +38,10 @@ height: data.readUInt32BE(8), | ||
}); | ||
parser.push(null); | ||
}); | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var once = require('../common').once; | ||
var Transform = require('readable-stream').Transform; | ||
@@ -126,4 +125,3 @@ | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var state = STATE_IDENTIFY; | ||
@@ -134,2 +132,3 @@ var data_len = 0; | ||
var parser = new Transform({ | ||
readableObjectMode: true, | ||
transform: function transform(chunk, encoding, next) { | ||
@@ -147,3 +146,3 @@ switch (state) { | ||
state = STATE_IGNORE; | ||
callback(); | ||
parser.push(null); | ||
} | ||
@@ -157,3 +156,3 @@ | ||
state = STATE_IGNORE; | ||
callback(); | ||
parser.push(null); | ||
} | ||
@@ -169,3 +168,4 @@ | ||
if (result) { | ||
callback(null, result); | ||
parser.push(result); | ||
parser.push(null); | ||
break; | ||
@@ -178,3 +178,3 @@ } | ||
state = STATE_IGNORE; | ||
callback(); | ||
parser.push(null); | ||
} | ||
@@ -190,9 +190,9 @@ | ||
state = STATE_IGNORE; | ||
callback(); | ||
parser.push(null); | ||
} | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -40,4 +39,3 @@ var sliceEq = require('../common').sliceEq; | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -50,3 +48,3 @@ | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -60,3 +58,3 @@ } | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -82,3 +80,3 @@ } | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
parser.push(null); | ||
return; | ||
@@ -104,3 +102,3 @@ } | ||
if (width && height) { | ||
callback(null, { | ||
parser.push({ | ||
width: width, | ||
@@ -114,2 +112,4 @@ height: height, | ||
} | ||
parser.push(null); | ||
}); | ||
@@ -120,5 +120,5 @@ }); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
@@ -6,3 +6,2 @@ 'use strict'; | ||
var ParserStream = require('../common').ParserStream; | ||
var once = require('../common').once; | ||
var str2arr = require('../common').str2arr; | ||
@@ -16,3 +15,3 @@ var sliceEq = require('../common').sliceEq; | ||
function parseVP8(parser, callback) { | ||
function parseVP8(parser) { | ||
parser._bytes(14, function (data) { | ||
@@ -23,7 +22,6 @@ parser._skipBytes(Infinity); | ||
// bad code block signature | ||
callback(); | ||
return; | ||
} | ||
callback(null, { | ||
parser.push({ | ||
width: data.readUInt16LE(10) & 0x3FFF, | ||
@@ -36,2 +34,4 @@ height: data.readUInt16LE(12) & 0x3FFF, | ||
}); | ||
parser.push(null); | ||
}); | ||
@@ -41,3 +41,3 @@ } | ||
function parseVP8L(parser, callback) { | ||
function parseVP8L(parser) { | ||
parser._bytes(9, function (data) { | ||
@@ -48,3 +48,2 @@ parser._skipBytes(Infinity); | ||
// bad code block signature | ||
callback(); | ||
return; | ||
@@ -55,3 +54,3 @@ } | ||
callback(null, { | ||
parser.push({ | ||
width: (bits & 0x3FFF) + 1, | ||
@@ -64,2 +63,4 @@ height: ((bits >> 14) & 0x3FFF) + 1, | ||
}); | ||
parser.push(null); | ||
}); | ||
@@ -69,7 +70,7 @@ } | ||
function parseVP8X(parser, callback) { | ||
function parseVP8X(parser) { | ||
parser._bytes(14, function (data) { | ||
parser._skipBytes(Infinity); | ||
callback(null, { | ||
parser.push({ | ||
// TODO: replace with `data.readUIntLE(8, 3) + 1` | ||
@@ -84,2 +85,4 @@ // when 0.10 support is dropped | ||
}); | ||
parser.push(null); | ||
}); | ||
@@ -89,4 +92,3 @@ } | ||
module.exports = function (input, _callback) { | ||
var callback = once(_callback); | ||
module.exports = function () { | ||
var parser = new ParserStream(); | ||
@@ -100,16 +102,15 @@ | ||
switch (data[15]) { | ||
case 32/*' '*/: parseVP8(parser, callback); return; | ||
case 76/* L */: parseVP8L(parser, callback); return; | ||
case 88/* X */: parseVP8X(parser, callback); return; | ||
case 32/*' '*/: parseVP8(parser); return; | ||
case 76/* L */: parseVP8L(parser); return; | ||
case 88/* X */: parseVP8X(parser); return; | ||
} | ||
} else { | ||
parser._skipBytes(Infinity); | ||
parser.push(null); | ||
} | ||
parser._skipBytes(Infinity); | ||
callback(); | ||
return; | ||
}); | ||
input.pipe(parser); | ||
parser.on('finish', function () { parser.push(null); }); | ||
return parser; | ||
}; |
{ | ||
"name": "probe-image-size", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Get image size without full download (JPG, GIF, PNG, WebP, BMP, TIFF, PSD)", | ||
@@ -41,3 +41,3 @@ "keywords": [ | ||
"coveralls": "^2.11.9", | ||
"eslint": "~2.13.1", | ||
"eslint": "~3.0.1", | ||
"from2": "^2.1", | ||
@@ -44,0 +44,0 @@ "istanbul": "^0.4.1", |
@@ -26,3 +26,2 @@ 'use strict'; | ||
var pending = 0; | ||
var pStreams = []; | ||
@@ -52,26 +51,27 @@ | ||
stream.on('error', function (err) { cleanup(); callback(err); }); | ||
stream.on('end', function () { cleanup(); callback(unrecognizedFormat()); }); | ||
Object.keys(parsers).forEach(function (type) { | ||
var pStream = parsers[type](); | ||
pending++; | ||
pStream.on('data', function (result) { | ||
callback(null, result); | ||
cleanup(); | ||
}); | ||
var pStream = parsers[type](stream, function (__, result) { | ||
pending--; | ||
pStream.on('error', function () { | ||
// silently ignore errors because user does not need to know | ||
// that something wrong is happening here | ||
}); | ||
pStream.on('end', function () { | ||
cleanup(pStream); | ||
if (result) { | ||
callback(null, result); | ||
return; | ||
} | ||
// No more active scanners & still no positive -> fail | ||
if (!pending) { | ||
if (pStreams.length === 0) { | ||
cleanup(); | ||
callback(unrecognizedFormat()); | ||
return; | ||
} | ||
}); | ||
stream.pipe(pStream); | ||
pStreams.push(pStream); | ||
@@ -78,0 +78,0 @@ }); |
40174
1087