From ec4980bf6a8b1b607ecded1cf0c27618088bec78 Mon Sep 17 00:00:00 2001 From: JacobLinCool Date: Wed, 1 Nov 2023 15:52:54 +0800 Subject: [PATCH] Add support for Mach-O (#615) --- core.d.ts | 2 ++ core.js | 7 +++++++ fixture/fixture.macho | Bin 0 -> 16833 bytes package.json | 1 + readme.md | 1 + supported.js | 2 ++ 6 files changed, 13 insertions(+) create mode 100755 fixture/fixture.macho diff --git a/core.d.ts b/core.d.ts index f79f7b7b..1f3cf074 100644 --- a/core.d.ts +++ b/core.d.ts @@ -50,6 +50,7 @@ export type FileExtension = | 'epub' | 'mobi' | 'elf' + | 'macho' | 'exe' | 'swf' | 'rtf' @@ -209,6 +210,7 @@ export type MimeType = | 'audio/amr' | 'application/pdf' | 'application/x-elf' + | 'application/x-mach-binary' | 'application/x-msdownload' | 'application/x-shockwave-flash' | 'application/rtf' diff --git a/core.js b/core.js index c3014494..8145965b 100644 --- a/core.js +++ b/core.js @@ -855,6 +855,13 @@ class FileTypeParser { }; } + if (this.check([0xCF, 0xFA, 0xED, 0xFE])) { + return { + ext: 'macho', + mime: 'application/x-mach-binary', + }; + } + // -- 5-byte signatures -- if (this.check([0x4F, 0x54, 0x54, 0x4F, 0x00])) { diff --git a/fixture/fixture.macho b/fixture/fixture.macho new file mode 100755 index 0000000000000000000000000000000000000000..17407f5888f271716e262a19a07214bd4cb9b3aa GIT binary patch literal 16833 zcmeI3O-NKx6vyw(I8dmmF@n58>dW1AqxX$`NvWlAAr1T#VxgG6oxy`})Tz^-ypJJ8_Ql4WV-OMbS zEwB$?yLCBGQT;Waa&A)VPRZmXE8jsmVJmQKC!_AiF-aEPkI&)XD^~cse1EQ4ci2jQ z2iw9dG|$nl_ORKKvoD9{3f5cQTgdSF0YiutWVh*eTT*P+<~QGAt%|LgId;8>+Kk`A&XZ?cd~jF!pJ(&v$*gq|$Ij&SqweG}TJ~ a4cGZcgU`;Do+y7mJ7Ww@-%I=6ANd1hSHGPA literal 0 HcmV?d00001 diff --git a/package.json b/package.json index ad155899..9e945b88 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "is", "exif", "elf", + "macho", "exe", "binary", "buffer", diff --git a/readme.md b/readme.md index cd50d930..aa0bc799 100644 --- a/readme.md +++ b/readme.md @@ -388,6 +388,7 @@ Returns a `Set` of supported MIME types. - [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks - [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store - [`m4v`](https://en.wikipedia.org/wiki/M4V) - Video container format developed by Apple, which is very similar to the MP4 format +- [`macho`](https://en.wikipedia.org/wiki/Mach-O) - Mach-O binary format - [`mid`](https://en.wikipedia.org/wiki/MIDI) - Musical Instrument Digital Interface file - [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information - [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000 diff --git a/supported.js b/supported.js index 6b2545f9..5b913777 100644 --- a/supported.js +++ b/supported.js @@ -48,6 +48,7 @@ export const extensions = [ 'pdf', 'epub', 'elf', + 'macho', 'exe', 'swf', 'rtf', @@ -206,6 +207,7 @@ export const mimeTypes = [ 'audio/amr', 'application/pdf', 'application/x-elf', + 'application/x-mach-binary', 'application/x-msdownload', 'application/x-shockwave-flash', 'application/rtf',