New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

exifreader

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exifreader - npm Package Compare versions

Comparing version

to
4.9.0

2

package.json
{
"name": "exifreader",
"version": "4.8.1",
"version": "4.9.0",
"description": "Library that parses Exif metadata in images.",

@@ -5,0 +5,0 @@ "author": "Mattias Wallander <mattias@wallander.eu>",

@@ -206,2 +206,24 @@ ExifReader

#### Read only part of file
If you only want to read part of the image file you can use the `length` option:
```javascript
const tags = await ExifReader.load(filename, {length: 128 * 1024});
```
This will load only the first 128 KiB of the file. This could be useful if you
know the metadata is located at the beginning of the file. Just be aware that
it's common for the metadata to be spread out over a larger area so please try
it out on your set of files to know if it's suitable for your situation.
Note that this option only works when ExifReader handles the loading of the
file. If e.g. a JavaScript File object from a form file field is passed into
ExifReader the whole file will already have been loaded into memory and it's too
late. More specifically the length option will work for 1. local files when
running through Node.js, and 2. remote files when passing a URL. For the latter,
if doing this through a web browser, make sure the remote server is either on
the same origin (domain) as your script or that the server is passing correct
CORS headers, specifically allowing the `Range` header.
#### Unknown tags

@@ -429,3 +451,4 @@

possibly Exif too if they come in an irregular order) so please check if
this optimization fits your use case.
this optimization fits your use case. Use the `length` option to only read
the beginning of the file. See above for more details on that.

@@ -432,0 +455,0 @@ Testing

@@ -37,3 +37,3 @@ /**

if (isFilePathOrURL(data)) {
return loadFile(data).then((fileContents) => loadFromData(fileContents, options));
return loadFile(data, options).then((fileContents) => loadFromData(fileContents, options));
}

@@ -50,22 +50,35 @@ if (isBrowserFileObject(data)) {

function loadFile(filename) {
function loadFile(filename, options) {
if (/^https?:\/\//.test(filename)) {
if (typeof fetch !== 'undefined') {
return browserFetchRemoteFile(filename);
return browserFetchRemoteFile(filename, options);
}
return nodeFetchRemoteFile(filename);
return nodeFetchRemoteFile(filename, options);
}
return loadLocalFile(filename);
return loadLocalFile(filename, options);
}
function browserFetchRemoteFile(url) {
return fetch(url).then((response) => response.arrayBuffer());
function browserFetchRemoteFile(url, {length} = {}) {
const options = {method: 'GET'};
if (Number.isInteger(length) && length >= 0) {
options.headers = {
range: `bytes=0-${length - 1}`,
};
}
return fetch(url, options).then((response) => response.arrayBuffer());
}
function nodeFetchRemoteFile(url) {
function nodeFetchRemoteFile(url, {length} = {}) {
return new Promise((resolve, reject) => {
const options = {};
if (Number.isInteger(length) && length >= 0) {
options.headers = {
range: `bytes=0-${length - 1}`,
};
}
const get = requireNodeGet(url);
get(url, (response) => {
get(url, options, (response) => {
if ((response.statusCode >= 200) && (response.statusCode <= 299)) {

@@ -91,3 +104,3 @@ const data = [];

function loadLocalFile(filename) {
function loadLocalFile(filename, {length} = {}) {
return new Promise((resolve, reject) => {

@@ -103,4 +116,9 @@ const fs = requireNodeFs();

} else {
const buffer = Buffer.alloc(stat.size);
fs.read(fd, {buffer}, (error) => {
const size = Math.min(stat.size, length !== undefined ? length : stat.size);
const buffer = Buffer.alloc(size);
const options = {
buffer,
length: size
};
fs.read(fd, options, (error) => {
if (error) {

@@ -107,0 +125,0 @@ reject(error);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet