Socket
Socket
Sign inDemoInstall

image-size

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-size - npm Package Compare versions

Comparing version 0.3.3 to 0.3.5

lib/types/svg.js

33

lib/index.js

@@ -19,3 +19,3 @@ 'use strict';

// TO-DO: make this adaptive based on the initial signature of the image
var bufferSize = 128*1024;
var MaxBufferSize = 128*1024;

@@ -39,6 +39,9 @@ function lookup (buffer, filepath) {

function asyncFileToBuffer (filepath, buffer, callback) {
function asyncFileToBuffer (filepath, callback) {
// open the file in read only mode
fs.open(filepath, 'r', function (err, descriptor) {
if (err) { return callback(err); }
var size = fs.fstatSync(descriptor).size;
var bufferSize = Math.min(size, MaxBufferSize);
var buffer = new Buffer(bufferSize);
// read first buffer block from the file, asynchronously

@@ -48,3 +51,5 @@ fs.read(descriptor, buffer, 0, bufferSize, 0, function (err) {

// close the file, we are done
fs.close(descriptor, callback);
fs.close(descriptor, function (err) {
callback(err, buffer);
});
});

@@ -54,7 +59,11 @@ });

function syncFileToBuffer (filepath, buffer) {
function syncFileToBuffer (filepath) {
// read from the file, synchronously
var descriptor = fs.openSync(filepath, 'r');
var size = fs.fstatSync(descriptor).size;
var bufferSize = Math.min(size, MaxBufferSize);
var buffer = new Buffer(bufferSize);
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
fs.closeSync(descriptor);
return buffer;
}

@@ -81,21 +90,19 @@

// create a buffer to read data in
var buffer = new Buffer(bufferSize);
if (typeof callback === 'function') {
asyncFileToBuffer(filepath, buffer, function (err) {
asyncFileToBuffer(filepath, function (err, buffer) {
if (err) { return callback(err); }
// return the dimensions
var dimensions;
try {
callback(null, lookup(buffer, filepath));
} catch (err) {
callback(err);
dimensions = lookup(buffer, filepath);
} catch (e) {
err = e;
}
callback(err, dimensions);
});
} else {
syncFileToBuffer(filepath, buffer);
// return the dimensions
var buffer = syncFileToBuffer(filepath);
return lookup(buffer, filepath);
}
};

@@ -9,5 +9,5 @@ 'use strict';

'psd',
// 'svg',
'svg',
'tiff',
'webp'
];
{
"name": "image-size",
"version": "0.3.3",
"version": "0.3.5",
"description": "get dimensions of any image file",
"main": "lib/index.js",
"engines": {
"node": ">=0.8.0"
"node": ">=0.10.0"
},

@@ -32,3 +32,4 @@ "bin": {

"tiff",
"webp"
"webp",
"svg"
],

@@ -41,9 +42,9 @@ "author": "netroy <aditya@netroy.in> (http://netroy.in/)",

"devDependencies": {
"escomplex-js": "~0.1.0",
"expect.js": "~0.2.0",
"glob": "~3.2.7",
"jshint": "~2.3.0",
"mocha": "~1.14.0",
"sinon": "~1.7.3"
"escomplex-js": "~0.1.4",
"expect.js": "~0.3.1",
"glob": "~4.0.6",
"jshint": "~2.5.6",
"mocha": "~1.21.5",
"sinon": "~1.10.3"
}
}

@@ -61,5 +61,5 @@ [![Build Status](https://travis-ci.org/netroy/image-size.png?branch=master)](https://travis-ci.org/netroy/image-size)

* WebP
* SVG
##### Upcoming
* SVG
* SWF

@@ -66,0 +66,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc