exifreader 4.47.0 → 4.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,7 @@ You can try it out on the
28
28
  | JPEG | **yes** | **yes** | **yes** | **yes** | **yes** | **some*** | **some**** | **yes** | **yes** |
29
29
  | JPEG XL*** | **yes** | no | **yes** | no | no | no | **some**** | ??? | **yes** |
30
30
  | TIFF | **yes** | **yes** | **yes** | **yes** | ??? | **some*** | **some**** | **yes** | N/A |
31
- | PNG | **yes** | **yes** | **yes** | **yes** | ??? | ??? | **some**** | no | **yes** |
31
+ | PNG | **yes** | **yes** | **yes** | **yes** | ??? | ??? | **some**** | **yes** | **yes** |
32
32
  | HEIC/HEIF | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | no |
33
33
  | AVIF | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | no |
34
34
  | WebP | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | **yes** |
@@ -53,18 +53,6 @@ You can try it out on the
53
53
  If you're missing something that you think should be supported, file an issue
54
54
  with an attached example image and I'll see what I can do.
55
55
 
56
- **Notes for exif-js users**
57
-
58
- If you come here from the popular but now dead exif-js package, please let me
59
- know if you're missing anything from it and I will try to help you. Some notes:
60
-
61
- - ExifReader has a different API, hopefully better. :-)
62
- - XMP support in exif-js does not seem perfect. ExifReader should be a bit
63
- better on that part.
64
- - ExifReader works with strict mode.
65
- - I've been maintaining this package since 2012 and I have no plans to stop
66
- doing that anytime soon.
67
-
68
56
  Table of Contents
69
57
  -----------------
70
58
 
@@ -217,8 +205,14 @@ to cross-site scripting. Use `textContent`, your framework's escaping, or a
217
205
  sanitizer such as DOMPurify when displaying metadata. The property names inside
218
206
  a tag value come from the image too, and a tag whose name is `__proto__` is kept
219
207
  under that name as a regular property, so it does not replace the prototype of
220
- the object holding it. A value parsed from an XMP `rdf:value` element that holds
221
- child elements other than a list is returned as an object without a prototype.
208
+ the object holding it. A tag whose name comes from the image and is the name of
209
+ an `Object.prototype` method, such as `hasOwnProperty`, `toString` or
210
+ `constructor`, is returned under that name with `_` appended
211
+ (`hasOwnProperty_`), so it does not hide the method on the result object or on
212
+ a group object, and `includeTags` and `excludeTags` match it by that returned
213
+ name. Property names inside a tag value are not changed in this way. A value
214
+ parsed from an XMP `rdf:value` element that holds child elements other than a
215
+ list is returned as an object without a prototype.
222
216
  Such an object has no inherited methods, and copying it into an object of your
223
217
  own with `Object.assign` or a deep merge helper without filtering the keys could
224
218
  let a crafted image replace that object's prototype.
@@ -394,6 +388,11 @@ make sure the remote server is either on the same origin (domain) as your script
394
388
  or that the server is passing correct CORS headers, specifically allowing the
395
389
  `Range` header.
396
390
 
391
+ For those inputs a fractional `length` is rounded down, and a `length` that is
392
+ not a finite non-negative number or `'auto'` (such as the string `'1024'`,
393
+ `NaN`, `Infinity` or a negative number) makes `load()` reject before anything
394
+ is read.
395
+
397
396
  #### Read only the metadata bytes (`length: 'auto'`)
398
397
 
399
398
  When you want to download or store just enough of an image to extract its
@@ -409,9 +408,10 @@ const tags = await ExifReader.load(url, {
409
408
 
410
409
  tags.metadataRange.end // exact byte count needed for the metadata
411
410
  tags.metadataRange.buffer // bytes [0, end), sliced from what we read.
412
- // Same kind as the input (ArrayBuffer or
413
- // Node Buffer). Save this to disk to keep
414
- // only the metadata-bearing prefix.
411
+ // Same kind as the input (ArrayBuffer,
412
+ // SharedArrayBuffer or Node Buffer). Save
413
+ // this to disk to keep only the
414
+ // metadata-bearing prefix.
415
415
  tags.metadataRange.fetched // bytes actually read. May be greater than
416
416
  // `end` because the loop reads in fixed-size
417
417
  // chunks and so may read a little past `end`.
@@ -431,10 +431,10 @@ Exif/XMP `iloc` entries point near the end of the file typically take two.
431
431
  - Local file path via Node `fs`
432
432
  - Browser `File` object via `File.slice`
433
433
 
434
- It is also accepted for in-memory inputs (`ArrayBuffer`, `Buffer`,
435
- `SharedArrayBuffer`, `DataView`) as a convenience. There is no IO loop to
436
- run in that case, but `metadataRange.buffer` is still attached as the
437
- trimmed slice of what you passed in.
434
+ It is also accepted for in-memory inputs (`ArrayBuffer`, `SharedArrayBuffer`
435
+ and Node.js `Buffer`) as a convenience. There is no IO loop to run in that
436
+ case, but `metadataRange.buffer` is still attached as the trimmed slice of
437
+ what you passed in.
438
438
 
439
439
  Requirements and caveats:
440
440
 
package/bin/build.js CHANGED
@@ -8,6 +8,7 @@ const os = require('os');
8
8
  const {execSync} = require('child_process');
9
9
  const dependentHasExifReaderConfig = require('./findDependentConfig');
10
10
  const {writeMarker, removeMarker} = require('./custom-build-marker');
11
+ const {unshareFile} = require('./unshare-file');
11
12
 
12
13
  const EXIFREADER_ROOT_DIR = path.join(__dirname, '..');
13
14
 
@@ -44,6 +45,8 @@ function runBuild(options) {
44
45
  const config = env.EXIFREADER_CUSTOM_BUILD ? JSON.parse(env.EXIFREADER_CUSTOM_BUILD) : dependentHasExifReaderConfig();
45
46
  const distDir = path.join(EXIFREADER_ROOT_DIR, 'dist');
46
47
  removeMarker(distDir);
48
+ unshareFile(path.join(distDir, 'exif-reader.js'));
49
+ unshareFile(path.join(distDir, 'exif-reader.js.map'));
47
50
 
48
51
  let tmpDir;
49
52
  try {
@@ -0,0 +1,29 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ const fs = require('fs');
6
+
7
+ module.exports = {unshareFile};
8
+
9
+ /**
10
+ * Give a hardlinked file its own inode with the same content, so that writing
11
+ * to it no longer changes the other links. A file with one link, or a missing
12
+ * file, is left alone.
13
+ *
14
+ * @param {string} filePath The file to unshare.
15
+ */
16
+ function unshareFile(filePath) {
17
+ // Package managers can hardlink package files from a shared store, and webpack writes in place.
18
+ if (!fs.existsSync(filePath) || fs.statSync(filePath).nlink <= 1) {
19
+ return;
20
+ }
21
+ const tmpPath = `${filePath}.${process.pid}.tmp`;
22
+ try {
23
+ fs.copyFileSync(filePath, tmpPath);
24
+ fs.renameSync(tmpPath, filePath);
25
+ } catch (error) {
26
+ fs.rmSync(tmpPath, {force: true});
27
+ throw error;
28
+ }
29
+ }