lib/image-size.js
function getImageSizeFromURL(url) {
	return new Promise((resolve, reject) => {
		url = parseUrl(url);
		const transport = url.protocol === 'https:' ? https : http;

		transport.get(url, resp => {
			const chunks = [];
			let bufSize = 0;

			const trySize = chunks => {
				try {
					const size = sizeOf(Buffer.concat(chunks, bufSize));
					resp.removeListener('data', onData);
					resp.destroy(); // no need to read further
					resolve(sizeForFileName(path.basename(url.pathname), size));
				} catch(err) {
					// might not have enough data, skip error
				}
			};

			const onData = chunk => {
				bufSize += chunk.length;
				chunks.push(chunk);
				trySize(chunks);
			};

			resp
			.on('data', onData)
			.on('end', () => trySize(chunks))
			.once('error', err => {
				resp.removeListener('data', onData);
				reject(err);
			});
		})
		.once('error', reject);
	});
}
function getImageSizeFromURL(url) {
	return new Promise((resolve, reject) => {
		url = parseUrl(url);
		const transport = url.protocol === 'https:' ? https : http;

		transport.get(url, resp => {
			const chunks = [];
			let bufSize = 0;

			const trySize = chunks => {
				try {
					const size = sizeOf(Buffer.concat(chunks, bufSize));
					resp.removeListener('data', onData);
					resp.destroy(); // no need to read further
					resolve(sizeForFileName(path.basename(url.pathname), size));
				} catch(err) {
					// might not have enough data, skip error
				}
			};

			const onData = chunk => {
				bufSize += chunk.length;
				chunks.push(chunk);
				trySize(chunks);
			};

			resp
			.on('data', onData)
			.on('end', () => trySize(chunks))
			.once('error', err => {
				resp.removeListener('data', onData);
				reject(err);
			});
		})
		.once('error', reject);
	});
}
function getImageSizeFromURL ( url ) { return new Promise ( ( resolve , reject ) => { url = parseUrl ( url ) ; const transport = url . protocol === 'https:' ? https : http ; transport . get ( url , resp => { const chunks = [ ] ; let bufSize = 0 ; const trySize = chunks => { try { const size = sizeOf ( Buffer . concat ( chunks , bufSize ) ) ; resp . removeListener ( 'data' , onData ) ; resp . destroy ( ) ; // no need to read further resolve ( sizeForFileName ( path . basename ( url . pathname ) , size ) ) ; } catch ( err ) { // might not have enough data, skip error } } ; const onData = chunk => { bufSize += chunk . length ; chunks . push ( chunk ) ; trySize ( chunks ) ; } ; resp . on ( 'data' , onData ) . on ( 'end' , ( ) => trySize ( chunks ) ) . once ( 'error' , err => { resp . removeListener ( 'data' , onData ) ; reject ( err ) ; } ) ; } ) . once ( 'error' , reject ) ; } ) ; }
Get image size from given remove URL
@param  {String} url
@return {Promise}
Get image size from given remove URL