You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

file-type-mime

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-type-mime - npm Package Compare versions

Comparing version

to
0.4.6

2

dist/index.js

@@ -1,1 +0,1 @@

function s(e,t=0){return l(e,t,2).getUint16(0,!0)}function c(e,t=0){return l(e,t,4).getUint32(0,!0)}function f(e,t=0,x=e.byteLength){let n=e.slice(t,t+x);return U.decode(new Uint8Array(n))}function m(e,t,x=0){if(e.length<t.length+x)return!1;for(let[n,i]of t.entries())if(i!==null&&i!==e[n+x])return!1;return!0}function l(e,t,x){let n=e.slice(t,t+x);return new DataView(new Uint8Array(n).buffer)}var U=new TextDecoder("utf8");var u=[["db","application/vnd.sqlite3",[83,81,76,105,116,101,32,102,111,114,109,97,116,32,51,0]],["woff","font/woff",[119,79,70,70]],["woff2","font/woff2",[119,79,70,50]],["bmp","image/bmp",[66,77]],["gif","image/gif",[71,73,70,56,55,97]],["gif","image/gif",[71,73,70,56,57,97]],["heic","image/heic",[102,116,121,112,104,101,105],{offset:4}],["heic","image/heic",[102,116,121,112,109],{offset:4}],["ico","image/x-icon",[0,0,1,0]],["jpg","image/jpeg",[255,216,255]],["pdf","application/pdf",[37,80,68,70,45]],["png","image/png",[137,80,78,71,13,10,26,10]],["7z","application/x-7z-compressed",[55,122,188,175,39,28]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,0]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,1,0]],["rtf","application/rtf",[123,92,114,116,102,49]],["bz2","application/x-bzip2",[66,90,104]],["gz","application/gzip",[31,139]],["tar","application/x-tar",[117,115,116,97,114,0,48,48],{offset:257}],["tar","application/x-tar",[117,115,116,97,114,32,32,0],{offset:257}],["tif","image/tiff",[73,73,42,0]],["tiff","image/tiff",[77,77,0,42]],["zip","application/zip",[80,75,3,4],{exact:!1}],["zip","application/zip",[80,75,5,6]],["mp3","audio/mp3",[255,251]],["mp3","audio/mp3",[255,243]],["mp3","audio/mp3",[255,242]],["mp3","audio/mp3",[73,68,51]],["mp4","video/mp4",[102,116,121,112,105,115,111,109],{offset:4}],["avi","video/x-msvideo",[82,73,70,70,null,null,null,null,65,86,73,32]],["wav","audio/wav",[82,73,70,70,null,null,null,null,87,65,86,69]],["ogx","application/ogg",[79,103,103,83],{exact:!1},[["oga","audio/ogg",[127,70,76,65,67],{offset:28}],["ogg","audio/ogg",[1,118,111,114,98,105,115],{offset:28}],["ogm","video/ogg",[1,118,105,100,101,111,0],{offset:28}],["ogv","video/ogg",[128,116,104,101,111,114,97],{offset:28}]]],["webp","image/webp",[82,73,70,70,null,null,null,null,87,69,66,80]],["psd","image/vnd.adobe.photoshop",[56,66,80,83]],["flac","audio/x-flac",[102,76,97,67]],["wasm","application/wasm",[0,97,115,109]],["deb","application/x-deb",[33,60,97,114,99,104,62,10]],["exe","application/x-msdownload",[77,90]],["exe","application/x-msdownload",[90,77]],["class","application/java-vm",[202,254,186,190]],["parquet","application/vnd.apache.parquet",[80,65,82,49]]];function L(e){for(let t=0;t<e.length;t++)try{let x=e.charCodeAt(t);if(x===65533||x<=8)return!1}catch{return!1}return!0}function d(e){try{let t=f(e);if(!L(t))return;try{return JSON.parse(t),{ext:"json",mime:"application/json"}}catch{return{ext:"txt",mime:"text/plain"}}}catch{return}}function g(e){return y(e).map(([t,x,n,{offset:i=0}={}])=>n.length+i).reduce((t,x)=>x>t?x:t,0)}function y(e){return e.flatMap(([t,x,n,i={},r=[]])=>[[t,x,n,i],...r])}function h(e,{ext:t,mime:x}){return t||x?y(e).filter(n=>n[0]===t||n[1]===x):[]}function v(e,t){let x=0;for(;x+30<e.byteLength;){let n=s(e,x+18),i=s(e,x+26),r=s(e,x+28),p=f(e,x+30,i),[o]=p.split("/"),a=p.endsWith(".xml");if(o==="extension.vsixmanifest")return{ext:"vsix",mime:"application/vsix"};if(o==="META-INF")return{ext:"jar",mime:"application/java-archive"};if(o==="ppt"&&a)return{ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"};if(o==="word"&&a)return{ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"};if(o==="xl"&&a)return{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"};if(o==="mimetype")return j(e,i)??t;x=x+30+i+r+n}return t}function j(e,t){let x=c(e,18),n=c(e,22),i=s(e,28);if(x===n){let r=f(e,30+t+i,x);if(r==="application/vnd.oasis.opendocument.presentation")return{ext:"odp",mime:r};if(r==="application/vnd.oasis.opendocument.spreadsheet")return{ext:"ods",mime:r};if(r==="application/vnd.oasis.opendocument.text")return{ext:"odt",mime:r};if(r==="application/epub+zip")return{ext:"epub",mime:r}}}var F=g(u);function b(e,{extra:t=!1,hint:x}={}){if(x){let i=h(u,x);if(i.length>0){let r=w(e,i);if(r!==void 0)return r}}let n=w(e,u);if(n)return n;if(t)return R(e)}function w(e,t){let x=new Uint8Array(e.slice(0,F));for(let[n,i,r,{exact:p=!0,offset:o=0}={},a=[]]of t)if(m(x,r,o)){if(n==="zip"&&!p)return v(e,{ext:n,mime:i});if(!p&&a.length){for(let[S,B,A,{offset:z=0}={}]of a)if(m(x,A,z))return{ext:S,mime:B}}return{ext:n,mime:i}}}function R(e){return d(e)}export{b as parse};
function s(e,t=0){return d(e,t,2).getUint16(0,!0)}function l(e,t=0){return d(e,t,4).getUint32(0,!0)}function f(e,t=0,i=e.byteLength){let x=e.slice(t,t+i);return L.decode(new Uint8Array(x))}function T(e,t=" "){return R.encode(e)}function k(e,t,i=0){let x=T(t);return c(e,x,i)}function u(e,t,i=0){return k(new Uint8Array(e.slice(i,t.length*8)),t)}function c(e,t,i=0){if(e.length<t.length+i)return!1;for(let[x,n]of t.entries())if(n!==null&&n!==e[x+i])return!1;return!0}function d(e,t,i){let x=e.slice(t,t+i);return new DataView(new Uint8Array(x).buffer)}var L=new TextDecoder("utf8"),R=new TextEncoder;function g(e){let t=i=>u(e,i,8);return t("qt")?{ext:"mov",mime:"video/quicktime"}:t("heic")?{ext:"heic",mime:"image/heic"}:t("avif")?{ext:"avif",mime:"image/avif"}:t("M4V")?{ext:"m4v",mime:"video/x-m4v"}:{ext:"mp4",mime:"video/mp4"}}var m=[["db","application/vnd.sqlite3",[83,81,76,105,116,101,32,102,111,114,109,97,116,32,51,0]],["woff","font/woff",[119,79,70,70]],["woff2","font/woff2",[119,79,70,50]],["bmp","image/bmp",[66,77]],["gif","image/gif",[71,73,70,56,55,97]],["gif","image/gif",[71,73,70,56,57,97]],["heic","image/heic",[102,116,121,112,104,101,105],{offset:4}],["heic","image/heic",[102,116,121,112,109],{offset:4}],["ico","image/x-icon",[0,0,1,0]],["jpg","image/jpeg",[255,216,255]],["pdf","application/pdf",[37,80,68,70,45]],["png","image/png",[137,80,78,71,13,10,26,10]],["7z","application/x-7z-compressed",[55,122,188,175,39,28]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,0]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,1,0]],["rtf","application/rtf",[123,92,114,116,102,49]],["bz2","application/x-bzip2",[66,90,104]],["gz","application/gzip",[31,139]],["tar","application/x-tar",[117,115,116,97,114,0,48,48],{offset:257}],["tar","application/x-tar",[117,115,116,97,114,32,32,0],{offset:257}],["tif","image/tiff",[73,73,42,0]],["tiff","image/tiff",[77,77,0,42]],["zip","application/zip",[80,75,3,4],{exact:!1}],["zip","application/zip",[80,75,5,6]],["mp3","audio/mp3",[255,251]],["mp3","audio/mp3",[255,243]],["mp3","audio/mp3",[255,242]],["mp3","audio/mp3",[73,68,51]],["mp4","video/mp4",[102,116,121,112,105,115,111,109],{offset:4}],["avi","video/x-msvideo",[82,73,70,70,null,null,null,null,65,86,73,32]],["wav","audio/wav",[82,73,70,70,null,null,null,null,87,65,86,69]],["ogx","application/ogg",[79,103,103,83],{exact:!1},[["oga","audio/ogg",[127,70,76,65,67],{offset:28}],["ogg","audio/ogg",[1,118,111,114,98,105,115],{offset:28}],["ogm","video/ogg",[1,118,105,100,101,111,0],{offset:28}],["ogv","video/ogg",[128,116,104,101,111,114,97],{offset:28}]]],["webp","image/webp",[82,73,70,70,null,null,null,null,87,69,66,80]],["psd","image/vnd.adobe.photoshop",[56,66,80,83]],["flac","audio/x-flac",[102,76,97,67]],["wasm","application/wasm",[0,97,115,109]],["deb","application/x-deb",[33,60,97,114,99,104,62,10]],["exe","application/x-msdownload",[77,90]],["exe","application/x-msdownload",[90,77]],["class","application/java-vm",[202,254,186,190]],["parquet","application/vnd.apache.parquet",[80,65,82,49]],["mov","video/quicktime",[102,114,101,101],{offset:4}],["mov","video/quicktime",[109,100,97,116],{offset:4}],["mov","video/quicktime",[109,111,111,118],{offset:4}],["mov","video/quicktime",[119,105,100,101],{offset:4}]];function q(e){for(let t=0;t<e.length;t++)try{let i=e.charCodeAt(t);if(i===65533||i<=8)return!1}catch{return!1}return!0}function y(e){try{let t=f(e);if(!q(t))return;try{return JSON.parse(t),{ext:"json",mime:"application/json"}}catch{return{ext:"txt",mime:"text/plain"}}}catch{return}}function v(e){return h(e).map(([t,i,x,{offset:n=0}={}])=>x.length+n).reduce((t,i)=>i>t?i:t,0)}function h(e){return e.flatMap(([t,i,x,n={},r=[]])=>[[t,i,x,n],...r])}function w(e,{ext:t,mime:i}){return t||i?h(e).filter(x=>x[0]===t||x[1]===i):[]}function S(e,t){let i=0;for(;i+30<e.byteLength;){let x=s(e,i+18),n=s(e,i+26),r=s(e,i+28),p=f(e,i+30,n),[o]=p.split("/"),a=p.endsWith(".xml");if(o==="extension.vsixmanifest")return{ext:"vsix",mime:"application/vsix"};if(o==="META-INF")return{ext:"jar",mime:"application/java-archive"};if(o==="ppt"&&a)return{ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"};if(o==="word"&&a)return{ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"};if(o==="xl"&&a)return{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"};if(o==="mimetype")return j(e,n)??t;i=i+30+n+r+x}return t}function j(e,t){let i=l(e,18),x=l(e,22),n=s(e,28);if(i===x){let r=f(e,30+t+n,i);if(r==="application/vnd.oasis.opendocument.presentation")return{ext:"odp",mime:r};if(r==="application/vnd.oasis.opendocument.spreadsheet")return{ext:"ods",mime:r};if(r==="application/vnd.oasis.opendocument.text")return{ext:"odt",mime:r};if(r==="application/epub+zip")return{ext:"epub",mime:r}}}var O=v(m);function b(e,{extra:t=!1,hint:i}={}){if(i){let n=w(m,i);if(n.length>0){let r=B(e,n);if(r!==void 0)return r}}if(u(e,"ftyp",4))return g(e);let x=B(e,m);if(x)return x;if(t)return M(e)}function B(e,t){let i=new Uint8Array(e.slice(0,O));for(let[x,n,r,{exact:p=!0,offset:o=0}={},a=[]]of t)if(c(i,r,o)){if(x==="zip"&&!p)return S(e,{ext:x,mime:n});if(!p&&a.length){for(let[A,U,z,{offset:F=0}={}]of a)if(c(i,z,F))return{ext:A,mime:U}}return{ext:x,mime:n}}}function M(e){return y(e)}export{b as parse};
{
"name": "file-type-mime",
"version": "0.4.5",
"version": "0.4.6",
"description": "Utility to parse mime type from a file content",

@@ -21,2 +21,12 @@ "homepage": "https://file-type-mime.vercel.app",

],
"scripts": {
"check": "biome check src",
"format": "biome format src --write",
"build": "tsup",
"test": "vitest run",
"execute": "node node-test.js",
"coverage": "vitest run --coverage",
"release": "pnpm build && pnpm publish",
"validate": "pnpm build && pnpm execute"
},
"keywords": [

@@ -39,3 +49,4 @@ "mime",

"application",
"zip"
"zip",
"ftyp"
],

@@ -53,8 +64,8 @@ "author": {

"@biomejs/biome": "^1.5.3",
"@types/node": "^20.11.17",
"@vitest/coverage-v8": "^2.0.0",
"@types/node": "^22.0.0",
"@vitest/coverage-v8": "^3.0.0",
"ts-node": "^10.9.2",
"tsup": "^8.1.0",
"typescript": "^5.3.3",
"vitest": "^2.0.0"
"vitest": "^3.0.0"
},

@@ -73,13 +84,3 @@ "nyc": {

"all": true
},
"scripts": {
"check": "biome check src",
"format": "biome format src --write",
"build": "tsup",
"test": "vitest run",
"execute": "node node-test.js",
"coverage": "vitest run --coverage",
"release": "pnpm build && pnpm publish",
"validate": "pnpm build && pnpm execute"
}
}
}

@@ -122,2 +122,5 @@ # file-type-mime

| vsix | application/vsix |
| mov | video/quicktime |
| afiv | image/avif |
| m4v | video/x-m4v |

@@ -124,0 +127,0 @@ ## License

Sorry, the diff of this file is not supported yet