mime-bytes 0.16.1 → 0.16.2

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.
@@ -10,8 +10,12 @@ export class FileTypeDetector {
10
10
  magicBytesCache;
11
11
  extensionCache;
12
12
  constructor(options = {}) {
13
- // Create a copy of FILE_TYPES to avoid modifying the global registry
14
- this.fileTypes = [...FILE_TYPES];
13
+ // Create a copy of FILE_TYPES sorted so that longer magic byte sequences
14
+ // are checked before shorter ones. This ensures that specific formats
15
+ // (e.g. HEIC with 8-byte signature "ftypheic") are matched before generic
16
+ // container formats (e.g. MP4 with 4-byte signature "ftyp") that share
17
+ // the same prefix.
18
+ this.fileTypes = [...FILE_TYPES].sort((a, b) => b.magicBytes.length - a.magicBytes.length);
15
19
  this.options = {
16
20
  peekBytes: options.peekBytes || 32,
17
21
  checkMultipleOffsets: options.checkMultipleOffsets !== false,
@@ -16,8 +16,12 @@ class FileTypeDetector {
16
16
  magicBytesCache;
17
17
  extensionCache;
18
18
  constructor(options = {}) {
19
- // Create a copy of FILE_TYPES to avoid modifying the global registry
20
- this.fileTypes = [...file_types_registry_1.FILE_TYPES];
19
+ // Create a copy of FILE_TYPES sorted so that longer magic byte sequences
20
+ // are checked before shorter ones. This ensures that specific formats
21
+ // (e.g. HEIC with 8-byte signature "ftypheic") are matched before generic
22
+ // container formats (e.g. MP4 with 4-byte signature "ftyp") that share
23
+ // the same prefix.
24
+ this.fileTypes = [...file_types_registry_1.FILE_TYPES].sort((a, b) => b.magicBytes.length - a.magicBytes.length);
21
25
  this.options = {
22
26
  peekBytes: options.peekBytes || 32,
23
27
  checkMultipleOffsets: options.checkMultipleOffsets !== false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mime-bytes",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Lightning-fast file type detection using magic bytes (file signatures) with a focus on stream processing and minimal memory usage",
6
6
  "main": "index.js",
@@ -33,5 +33,5 @@
33
33
  "glob": "^13.0.6",
34
34
  "makage": "^0.3.0"
35
35
  },
36
- "gitHead": "d43f1d7e38cc39a71b4f8d2cafb39f46df12e31a"
36
+ "gitHead": "51db78365ddc99139e4f63343fea2c8406c79e60"
37
37
  }