probe-image-size
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -0,1 +1,9 @@ | ||
1.1.0 / 2016-05-25 | ||
------------------ | ||
- Added promise support. | ||
- Use `readable-stream` instead of `stream`. | ||
- Reorganised internal files structure & tests. | ||
1.0.6 / 2016-04-13 | ||
@@ -2,0 +10,0 @@ ------------------ |
'use strict'; | ||
var Transform = require('stream').Transform; | ||
var Transform = require('readable-stream').Transform; | ||
var streamParser = require('stream-parser'); | ||
@@ -29,1 +29,19 @@ var inherits = require('util').inherits; | ||
}; | ||
exports.sliceEq = function (src, start, dest) { | ||
for (var i = start, j = 0; j < dest.length;) { | ||
if (src[i++] !== dest[j++]) return false; | ||
} | ||
return true; | ||
}; | ||
exports.str2arr = function (str) { | ||
var arr = new Array(str.length); | ||
for (var i = 0; i < arr.length; i++) { | ||
/* eslint-disable no-bitwise */ | ||
arr[i] = str.charCodeAt(i) & 0xFF; | ||
} | ||
return arr; | ||
}; |
@@ -11,9 +11,9 @@ | ||
var parsers = { | ||
bmp: require('./parsers/bmp'), | ||
gif: require('./parsers/gif'), | ||
jpeg: require('./parsers/jpeg'), | ||
png: require('./parsers/png'), | ||
psd: require('./parsers/psd'), | ||
tiff: require('./parsers/tiff'), | ||
webp: require('./parsers/webp') | ||
bmp: require('./parse_stream/bmp'), | ||
gif: require('./parse_stream/gif'), | ||
jpeg: require('./parse_stream/jpeg'), | ||
png: require('./parse_stream/png'), | ||
psd: require('./parse_stream/psd'), | ||
tiff: require('./parse_stream/tiff'), | ||
webp: require('./parse_stream/webp') | ||
}; | ||
@@ -70,4 +70,3 @@ | ||
/* eslint-disable eqeqeq */ | ||
if (length == +length) { | ||
if (length && length.match(/^\d+$/)) { | ||
result.length = +length; | ||
@@ -94,14 +93,36 @@ } | ||
// Cache for promise implementation | ||
var P; | ||
/////////////////////////////////////////////////////////////////////// | ||
// Exports | ||
// | ||
/* eslint-disable consistent-return */ | ||
module.exports = function get_image_size(src, callback) { | ||
var prober; | ||
if (typeof src.on === 'function' && typeof src.emit === 'function') { | ||
// looks like an EventEmitter, treating it as a stream | ||
probeStream(src, callback); | ||
prober = probeStream; | ||
} else { | ||
probeHttp(src, callback); | ||
prober = probeHttp; | ||
} | ||
if (!callback) { | ||
P = P || require('any-promise'); | ||
return new P(function (resolve, reject) { | ||
prober(src, function (err, data) { | ||
if (err) reject(err); | ||
else resolve(data); | ||
}); | ||
}); | ||
} | ||
prober(src, callback); | ||
}; | ||
module.exports.parsers = parsers; |
{ | ||
"name": "probe-image-size", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Get image size without full download (JPG, GIF, PNG, WebP, BMP, TIFF, PSD)", | ||
@@ -27,3 +27,5 @@ "keywords": [ | ||
"dependencies": { | ||
"any-promise": "^1.3.0", | ||
"async": "^1.4.2", | ||
"readable-stream": "^2.1.4", | ||
"request": "^2.60.0", | ||
@@ -30,0 +32,0 @@ "stream-parser": "~0.3.1" |
@@ -36,2 +36,8 @@ probe-image-size | ||
// With Promise | ||
// | ||
probe('http://example.com/image.jpg').then(function (result) { | ||
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg' } | ||
}); | ||
// From the stream | ||
@@ -54,3 +60,3 @@ // | ||
### probe(src, callback(err, result)) | ||
### probe(src [, callback(err, result)]) | ||
@@ -81,2 +87,4 @@ `src` can be of this types: | ||
If callback not provided, `Promise` will be returned. | ||
__Note.__ If you use stream as source, it's your responsibility to terminate | ||
@@ -83,0 +91,0 @@ reading in callback. That will release resources as soon as possible. On |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19692
505
103
5
1
+ Addedany-promise@^1.3.0
+ Addedreadable-stream@^2.1.4
+ Addedany-promise@1.3.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)