diff --git a/core.d.ts b/core.d.ts index 40065078..102e8343 100644 --- a/core.d.ts +++ b/core.d.ts @@ -140,7 +140,8 @@ export type FileExtension = | '3mf' | 'zst' | 'jxl' - | 'vcf'; + | 'vcf' + | 'jls'; export type MimeType = | 'image/jpeg' @@ -276,7 +277,8 @@ export type MimeType = | 'application/vnd.ms-htmlhelp' | 'model/3mf' | 'image/jxl' - | 'application/zstd'; + | 'application/zstd' + | 'image/jls'; export type FileTypeResult = { /** diff --git a/core.js b/core.js index 08bea57d..9dc2793d 100644 --- a/core.js +++ b/core.js @@ -159,13 +159,6 @@ class FileTypeParser { }; } - if (this.check([0xFF, 0xD8, 0xFF])) { - return { - ext: 'jpg', - mime: 'image/jpeg', - }; - } - if (this.check([0x49, 0x49, 0xBC])) { return { ext: 'jxr', @@ -222,6 +215,21 @@ class FileTypeParser { // -- 4-byte signatures -- + // Requires a sample size of 4 bytes + if (this.check([0xFF, 0xD8, 0xFF])) { + if (this.check([0xF7], {offset: 3})) { // JPG7/SOF55, indicating a ISO/IEC 14495 / JPEG-LS file + return { + ext: 'jls', + mime: 'image/jls', + }; + } + + return { + ext: 'jpg', + mime: 'image/jpeg', + }; + } + if (this.checkString('FLIF')) { return { ext: 'flif', diff --git a/fixture/fixture-hp1.jls b/fixture/fixture-hp1.jls new file mode 100644 index 00000000..d7ea94e1 Binary files /dev/null and b/fixture/fixture-hp1.jls differ diff --git a/fixture/fixture-hp2.jls b/fixture/fixture-hp2.jls new file mode 100644 index 00000000..4641bb65 Binary files /dev/null and b/fixture/fixture-hp2.jls differ diff --git a/fixture/fixture-hp3.jls b/fixture/fixture-hp3.jls new file mode 100644 index 00000000..be452833 Binary files /dev/null and b/fixture/fixture-hp3.jls differ diff --git a/fixture/fixture-normal.jls b/fixture/fixture-normal.jls new file mode 100644 index 00000000..44445571 Binary files /dev/null and b/fixture/fixture-normal.jls differ diff --git a/package.json b/package.json index 8aab8caf..97a9d224 100644 --- a/package.json +++ b/package.json @@ -193,7 +193,8 @@ "3mf", "zst", "jxl", - "vcf" + "vcf", + "jls" ], "dependencies": { "readable-web-to-node-stream": "^3.0.2", diff --git a/readme.md b/readme.md index 180706f4..61e80b68 100644 --- a/readme.md +++ b/readme.md @@ -397,6 +397,7 @@ Returns a `Set` of supported MIME types. - [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar - [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign document - [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker +- [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images - [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000 - [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image - [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000 diff --git a/supported.js b/supported.js index e96bb235..341b4a1e 100644 --- a/supported.js +++ b/supported.js @@ -138,6 +138,7 @@ export const extensions = [ 'zst', 'jxl', 'vcf', + 'jls', ]; export const mimeTypes = [ @@ -275,4 +276,5 @@ export const mimeTypes = [ 'model/3mf', 'image/jxl', 'application/zstd', + 'image/jls', ]; diff --git a/test.js b/test.js index 9466ece8..d9e18cd7 100644 --- a/test.js +++ b/test.js @@ -229,6 +229,12 @@ const names = { 'fixture-utf16-be-bom', // UTF-16 little endian encoded XML, with BOM 'fixture-utf16-le-bom', // UTF-16 big endian encoded XML, with BOM ], + jls: [ + 'fixture-normal', + 'fixture-hp1', + 'fixture-hp2', + 'fixture-hp3', + ], }; // Define an entry here only if the file type has potential