{"version":3,"file":"index.cjs","names":["samples"],"sources":["../src/bytes.ts","../src/ftyp.ts","../src/signatures.ts","../src/txt.ts","../src/utils.ts","../src/zip.ts","../src/parse.ts"],"sourcesContent":["export function getUint16(buffer: ArrayBuffer, offset = 0) {\n  const view = getBufferView(buffer, offset, 2);\n  return view.getUint16(0, true);\n}\n\nexport function getUint32(buffer: ArrayBuffer, offset = 0) {\n  const view = getBufferView(buffer, offset, 4);\n  return view.getUint32(0, true);\n}\n\nexport function getString(\n  buffer: ArrayBuffer,\n  offset = 0,\n  length = buffer.byteLength,\n) {\n  const slice = buffer.slice(offset, offset + length);\n  return decoder.decode(new Uint8Array(slice));\n}\n\nexport function bytesToHex(array: Uint8Array, separator = \" \") {\n  const parts = [...array].map((x) => x.toString(16).padStart(2, \"0\"));\n  return parts.join(separator);\n}\n\nexport function stringToBytes(value: string) {\n  return encoder.encode(value);\n}\n\nexport function compareString(array: Uint8Array, value: string, offset = 0) {\n  const bytes = stringToBytes(value);\n  return compareBytes(array, bytes, offset);\n}\n\nexport function containsString(buffer: ArrayBuffer, value: string, offset = 0) {\n  return compareString(\n    new Uint8Array(buffer.slice(offset, value.length * 8)),\n    value,\n  );\n}\n\nexport function compareBytes(\n  source: Uint8Array | number[],\n  sample: Uint8Array | (number | null)[],\n  offset = 0,\n) {\n  if (source.length < sample.length + offset) {\n    return false;\n  }\n\n  for (const [i, element] of sample.entries()) {\n    if (element === null) continue;\n    if (element !== source[i + offset]) {\n      return false;\n    }\n  }\n\n  return true;\n}\n\nfunction getBufferView(buffer: ArrayBuffer, offset: number, length: number) {\n  const slice = buffer.slice(offset, offset + length);\n  return new DataView(new Uint8Array(slice).buffer);\n}\n\nconst decoder = new TextDecoder(\"utf8\");\nconst encoder = new TextEncoder();\n","import { containsString } from \"./bytes\";\nimport type { Result } from \"./types\";\n\n// https://en.wikipedia.org/wiki/Container_format\n// https://en.wikipedia.org/wiki/ISO_base_media_file_format\n\nexport function parseFileTypeBoxFiles(buffer: ArrayBuffer): Result | undefined {\n  const is = (value: string) => containsString(buffer, value, 8);\n  if (is(\"qt\")) {\n    return { ext: \"mov\", mime: \"video/quicktime\" };\n  }\n  if (is(\"heic\")) {\n    return { ext: \"heic\", mime: \"image/heic\" };\n  }\n  if (is(\"avif\")) {\n    return { ext: \"avif\", mime: \"image/avif\" };\n  }\n  if (is(\"M4V\")) {\n    return { ext: \"m4v\", mime: \"video/x-m4v\" };\n  }\n  if (is(\"M4A\")) {\n    return { ext: \"m4a\", mime: \"audio/mp4\" };\n  }\n  // if (is('M4P')) {\n  //   return { ext: 'm4p', mime: 'video/mp4' };\n  // }\n  return { ext: \"mp4\", mime: \"video/mp4\" };\n}\n","// https://en.wikipedia.org/wiki/List_of_file_signatures\n// https://en.wikipedia.org/wiki/List_of_archive_formats\n// https://www.iana.org/assignments/media-types/media-types.xhtml\n\nexport type Options = { exact?: boolean; offset?: number };\nexport type BaseSignature =\n  | [string, string, (number | null)[]]\n  | [string, string, (number | null)[], Options];\nexport type Signature =\n  | BaseSignature\n  | [string, string, (number | null)[], Options, BaseSignature[]];\n\nexport const signatures: Signature[] = [\n  [\n    \"db\",\n    \"application/vnd.sqlite3\",\n    [\n      0x53, 0x51, 0x4c, 0x69, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61,\n      0x74, 0x20, 0x33, 0x00,\n    ],\n  ],\n  [\"woff\", \"font/woff\", [0x77, 0x4f, 0x46, 0x46]],\n  [\"woff2\", \"font/woff2\", [0x77, 0x4f, 0x46, 0x32]],\n  [\"bmp\", \"image/bmp\", [0x42, 0x4d]],\n  [\"gif\", \"image/gif\", [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]],\n  [\"gif\", \"image/gif\", [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]],\n  [\n    \"heic\",\n    \"image/heic\",\n    [0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69],\n    { offset: 4 },\n  ],\n  [\"heic\", \"image/heic\", [0x66, 0x74, 0x79, 0x70, 0x6d], { offset: 4 }],\n  [\"ico\", \"image/x-icon\", [0x00, 0x00, 0x01, 0x00]],\n  [\"jpg\", \"image/jpeg\", [0xff, 0xd8, 0xff]],\n  [\"pdf\", \"application/pdf\", [0x25, 0x50, 0x44, 0x46, 0x2d]],\n  [\"png\", \"image/png\", [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]],\n  [\"7z\", \"application/x-7z-compressed\", [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]],\n  [\n    \"rar\",\n    \"application/x-rar-compressed\",\n    [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00],\n  ],\n  [\n    \"rar\",\n    \"application/x-rar-compressed\",\n    [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00],\n  ],\n  [\"rtf\", \"application/rtf\", [0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31]],\n  [\"bz2\", \"application/x-bzip2\", [0x42, 0x5a, 0x68]],\n  [\"gz\", \"application/gzip\", [0x1f, 0x8b]],\n  [\n    \"tar\",\n    \"application/x-tar\",\n    [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30],\n    { offset: 257 },\n  ],\n  [\n    \"tar\",\n    \"application/x-tar\",\n    [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00],\n    { offset: 257 },\n  ],\n  [\"tif\", \"image/tiff\", [0x49, 0x49, 0x2a, 0x00]],\n  [\"tiff\", \"image/tiff\", [0x4d, 0x4d, 0x00, 0x2a]],\n  [\"zip\", \"application/zip\", [0x50, 0x4b, 0x03, 0x04], { exact: false }],\n  [\"zip\", \"application/zip\", [0x50, 0x4b, 0x05, 0x06]],\n  [\"mp3\", \"audio/mp3\", [0xff, 0xfb]],\n  [\"mp3\", \"audio/mp3\", [0xff, 0xf3]],\n  [\"mp3\", \"audio/mp3\", [0xff, 0xf2]],\n  [\"mp3\", \"audio/mp3\", [0x49, 0x44, 0x33]],\n  [\n    \"mp4\",\n    \"video/mp4\",\n    [0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6f, 0x6d],\n    { offset: 4 },\n  ],\n  [\n    \"avi\",\n    \"video/x-msvideo\",\n    [0x52, 0x49, 0x46, 0x46, null, null, null, null, 0x41, 0x56, 0x49, 0x20],\n  ],\n  [\n    \"wav\",\n    \"audio/wav\",\n    [0x52, 0x49, 0x46, 0x46, null, null, null, null, 0x57, 0x41, 0x56, 0x45],\n  ],\n  [\n    \"ogx\",\n    \"application/ogg\",\n    [0x4f, 0x67, 0x67, 0x53],\n    { exact: false },\n    [\n      [\"oga\", \"audio/ogg\", [0x7f, 0x46, 0x4c, 0x41, 0x43], { offset: 28 }],\n      [\n        \"ogg\",\n        \"audio/ogg\",\n        [0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73],\n        { offset: 28 },\n      ],\n      [\n        \"ogm\",\n        \"video/ogg\",\n        [0x01, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x00],\n        { offset: 28 },\n      ],\n      [\n        \"ogv\",\n        \"video/ogg\",\n        [0x80, 0x74, 0x68, 0x65, 0x6f, 0x72, 0x61],\n        { offset: 28 },\n      ],\n    ],\n  ],\n  [\n    \"webp\",\n    \"image/webp\",\n    [0x52, 0x49, 0x46, 0x46, null, null, null, null, 0x57, 0x45, 0x42, 0x50],\n  ],\n  [\"psd\", \"image/vnd.adobe.photoshop\", [0x38, 0x42, 0x50, 0x53]],\n  [\"flac\", \"audio/x-flac\", [0x66, 0x4c, 0x61, 0x43]],\n  [\"wasm\", \"application/wasm\", [0x00, 0x61, 0x73, 0x6d]],\n  [\n    \"deb\",\n    \"application/x-deb\",\n    [0x21, 0x3c, 0x61, 0x72, 0x63, 0x68, 0x3e, 0x0a],\n  ],\n  [\"exe\", \"application/x-msdownload\", [0x4d, 0x5a]],\n  [\"exe\", \"application/x-msdownload\", [0x5a, 0x4d]],\n  [\"class\", \"application/java-vm\", [0xca, 0xfe, 0xba, 0xbe]],\n  [\"parquet\", \"application/vnd.apache.parquet\", [0x50, 0x41, 0x52, 0x31]],\n  [\"mov\", \"video/quicktime\", [0x66, 0x72, 0x65, 0x65], { offset: 4 }],\n  [\"mov\", \"video/quicktime\", [0x6d, 0x64, 0x61, 0x74], { offset: 4 }],\n  [\"mov\", \"video/quicktime\", [0x6d, 0x6f, 0x6f, 0x76], { offset: 4 }],\n  [\"mov\", \"video/quicktime\", [0x77, 0x69, 0x64, 0x65], { offset: 4 }],\n  [\"zst\", \"application/zstd\", [0x28, 0xb5, 0x2f, 0xfd]],\n  [\"xz\", \"application/x-xz\", [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]],\n  [\"dmg\", \"application/x-apple-diskimage\", [0x78, 0x01]],\n  [\"Z\", \"application/x-compress\", [0x1f, 0xa0]],\n  [\"Z\", \"application/x-compress\", [0x1f, 0x9d]],\n  [\"ac3\", \"audio/vnd.dolby.dd-raw\", [0x0b, 0x77]],\n  [\"lz\", \"application/lzip\", [0x4c, 0x5a, 0x49, 0x50]],\n  [\"xml\", \"application/xml\", [0x3c, 0x3f, 0x78, 0x6d, 0x6c]],\n  [\"nes\", \"application/x-nintendo-nes-rom\", [0x4e, 0x45, 0x53, 0x1a]],\n];\n","import { getString } from \"./bytes\";\n\nexport function isText(data: string) {\n  for (let i = 0; i < data.length; i++) {\n    try {\n      const code = data.charCodeAt(i);\n      // 65533 is the unknown char\n      // 8 and below are control chars\n      if (code === 65533 || code <= 8) {\n        return false;\n      }\n    } catch {\n      return false;\n    }\n  }\n\n  return true;\n}\n\nexport function parseTxtLikeFiles(buffer: ArrayBuffer) {\n  try {\n    const data = getString(buffer);\n    if (!isText(data)) {\n      return undefined;\n    }\n    try {\n      JSON.parse(data);\n      return { ext: \"json\", mime: \"application/json\" };\n    } catch {\n      return { ext: \"txt\", mime: \"text/plain\" };\n    }\n  } catch {\n    return undefined;\n  }\n}\n","import type { BaseSignature, Signature } from \"./signatures\";\n\nexport function getUpperLimit(signatures: Signature[]) {\n  return flatten(signatures)\n    .map(([_ext, _mime, sample, { offset = 0 } = {}]) => sample.length + offset)\n    .reduce((lim, val) => (val > lim ? val : lim), 0);\n}\n\nexport function flatten(signatures: Signature[]): BaseSignature[] {\n  return signatures.flatMap(\n    ([ext, mime, bytes, options = {}, subSignatures = []]) => [\n      [ext, mime, bytes, options],\n      ...subSignatures,\n    ],\n  );\n}\n\nexport function findMatches(\n  signatures: Signature[],\n  { ext, mime }: { ext?: string; mime?: string },\n): BaseSignature[] {\n  if (!(ext || mime)) return [];\n  return flatten(signatures).filter(\n    (signature) => signature[0] === ext || signature[1] === mime,\n  );\n}\n","import { getString, getUint16, getUint32 } from \"./bytes\";\nimport type { Result } from \"./types\";\n\n// https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers\n\nexport function parseZipLikeFiles(\n  buffer: ArrayBuffer,\n  result: { ext: string; mime: string },\n): Result | undefined {\n  let offset = 0;\n  while (offset + 30 < buffer.byteLength) {\n    const rest = getUint16(buffer, offset + 18);\n    const size = getUint16(buffer, offset + 26);\n    const skip = getUint16(buffer, offset + 28);\n    const name = getString(buffer, offset + 30, size);\n    const [identifier] = name.split(\"/\");\n    const xmlFormat = name.endsWith(\".xml\");\n\n    if (identifier === \"extension.vsixmanifest\") {\n      return {\n        ext: \"vsix\",\n        mime: \"application/vsix\",\n      };\n    }\n\n    if (identifier === \"META-INF\") {\n      return {\n        ext: \"jar\",\n        mime: \"application/java-archive\",\n      };\n    }\n\n    if (identifier === \"ppt\" && xmlFormat) {\n      return {\n        ext: \"pptx\",\n        mime: \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n      };\n    }\n\n    if (identifier === \"word\" && xmlFormat) {\n      return {\n        ext: \"docx\",\n        mime: \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n      };\n    }\n\n    if (identifier === \"xl\" && xmlFormat) {\n      return {\n        ext: \"xlsx\",\n        mime: \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n      };\n    }\n\n    if (identifier === \"mimetype\") {\n      return parseOpenDocumentFile(buffer, size) ?? result;\n    }\n\n    offset = offset + 30 + size + skip + rest;\n  }\n\n  return result;\n}\n\nfunction parseOpenDocumentFile(\n  buffer: ArrayBuffer,\n  offset: number,\n): Result | undefined {\n  const compressedSize = getUint32(buffer, 18);\n  const uncompressedSize = getUint32(buffer, 22);\n  const extraFieldLength = getUint16(buffer, 28);\n\n  if (compressedSize === uncompressedSize) {\n    const mime = getString(\n      buffer,\n      30 + offset + extraFieldLength,\n      compressedSize,\n    );\n\n    if (mime === \"application/vnd.oasis.opendocument.presentation\") {\n      return {\n        ext: \"odp\",\n        mime,\n      };\n    }\n\n    if (mime === \"application/vnd.oasis.opendocument.spreadsheet\") {\n      return {\n        ext: \"ods\",\n        mime,\n      };\n    }\n\n    if (mime === \"application/vnd.oasis.opendocument.text\") {\n      return {\n        ext: \"odt\",\n        mime,\n      };\n    }\n\n    if (mime === \"application/epub+zip\") {\n      return {\n        ext: \"epub\",\n        mime,\n      };\n    }\n  }\n\n  return undefined;\n}\n","import { compareBytes, containsString } from \"./bytes\";\nimport { parseFileTypeBoxFiles } from \"./ftyp\";\nimport { type Signature, signatures as samples } from \"./signatures\";\nimport { parseTxtLikeFiles } from \"./txt\";\nimport type { Options, Result } from \"./types\";\nimport { findMatches, getUpperLimit } from \"./utils\";\nimport { parseZipLikeFiles } from \"./zip\";\n\n// Upper limit needs to be not less than the longest sample + offset\nconst UPPER_LIMIT = getUpperLimit(samples);\n\nexport default function parse(\n  buffer: ArrayBuffer,\n  { extra = false, hint }: Options = {},\n): Result | undefined {\n  // use the hint to short-circuit the parsing\n  // in case it's incorect - continue main flow\n  if (hint) {\n    const matches = findMatches(samples, hint);\n    if (matches.length > 0) {\n      const result = parseBytes(buffer, matches);\n      if (result !== undefined) {\n        return result;\n      }\n    }\n  }\n\n  if (containsString(buffer, \"ftyp\", 4)) {\n    return parseFileTypeBoxFiles(buffer);\n  }\n\n  const result = parseBytes(buffer, samples);\n\n  if (result) {\n    return result;\n  }\n\n  if (extra) {\n    return parseExtraTypes(buffer);\n  }\n\n  return undefined;\n}\n\nfunction parseBytes(\n  buffer: ArrayBuffer,\n  signatures: Signature[],\n): Result | undefined {\n  const bytes = new Uint8Array(buffer.slice(0, UPPER_LIMIT));\n  for (const [\n    ext,\n    mime,\n    sample,\n    { exact = true, offset = 0 } = {},\n    subSignatures = [],\n  ] of signatures) {\n    if (compareBytes(bytes, sample, offset)) {\n      if (ext === \"zip\" && !exact) {\n        // pass full buffer to zip parser\n        return parseZipLikeFiles(buffer, { ext, mime });\n      }\n\n      if (!exact && subSignatures.length) {\n        for (const [ext, mime, sample, { offset = 0 } = {}] of subSignatures) {\n          if (compareBytes(bytes, sample, offset)) {\n            return { ext, mime };\n          }\n        }\n      }\n\n      return { ext, mime };\n    }\n  }\n\n  return undefined;\n}\n\nfunction parseExtraTypes(buffer: ArrayBuffer): Result | undefined {\n  return parseTxtLikeFiles(buffer);\n}\n"],"mappings":"mEAAA,SAAgB,EAAU,EAAqB,EAAS,EAAG,CAEzD,OADa,EAAc,EAAQ,EAAQ,CACjC,CAAC,CAAC,UAAU,EAAG,EAAI,CAC/B,CAEA,SAAgB,EAAU,EAAqB,EAAS,EAAG,CAEzD,OADa,EAAc,EAAQ,EAAQ,CACjC,CAAC,CAAC,UAAU,EAAG,EAAI,CAC/B,CAEA,SAAgB,EACd,EACA,EAAS,EACT,EAAS,EAAO,WAChB,CACA,IAAM,EAAQ,EAAO,MAAM,EAAQ,EAAS,CAAM,EAClD,OAAO,EAAQ,OAAO,IAAI,WAAW,CAAK,CAAC,CAC7C,CAOA,SAAgB,EAAc,EAAe,CAC3C,OAAO,EAAQ,OAAO,CAAK,CAC7B,CAEA,SAAgB,EAAc,EAAmB,EAAe,EAAS,EAAG,CAE1E,OAAO,EAAa,EADN,EAAc,CACG,EAAG,CAAM,CAC1C,CAEA,SAAgB,EAAe,EAAqB,EAAe,EAAS,EAAG,CAC7E,OAAO,EACL,I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