forked from nodeca/probe-image-size
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (27 loc) · 805 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var probeStream = require('./stream');
var probeHttp = require('./http');
// Cache for promise implementation
var P;
/* 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
prober = probeStream;
} else {
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 = require('./lib/parsers_stream');
module.exports.sync = require('./sync');