-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
Hi,
when we give a filename to the library, it use fs.readfile to open the file.
Looks like the whole file is open, which is slow for big pictures.
I suggest that we first open the header of the picture and then read only the bytes corresponding to the exif part.
I would love to submit a pull request for this, but since there is not unit test (issue #26), I am not sure not to break anything.
I am thinking about something like :
var firstReadLength=6;
fs.open(image, 'r', function(err, fd) {
var data = new Buffer(firstReadLength);
fs.read(fd, data, 0, firstReadLength, null, function(err, length, buffer) {
if (buffer[0] == 0xFF && buffer[1] == 0xd8) {
if (buffer[2] == 0xff && buffer[3] == 0xe1) {
var length = buffer.readUInt16BE(4);
var exifBuffer = new Buffer(length);
fs.read(fd, exifBuffer, 0, length , 0, function(err, length, buffer) {
processImage(buffer, callback);
});
}
}
}
In my case, this lead to significant performance improvement : >*6 with pictures of around 7MB each (dont forget to drop your cache when doing this kind of performance analysis )
echo 3 | sudo tee /proc/sys/vm/drop_caches
Metadata
Metadata
Assignees
Labels
No labels