react-smart-copy 1.19.1 → 1.21.0
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.
- package/README.md +165 -0
- package/dist/files.cjs +948 -0
- package/dist/files.cjs.map +1 -0
- package/dist/files.d.cts +311 -0
- package/dist/files.d.ts +311 -0
- package/dist/files.js +932 -0
- package/dist/files.js.map +1 -0
- package/dist/secrets.cjs +551 -0
- package/dist/secrets.cjs.map +1 -0
- package/dist/secrets.d.cts +152 -0
- package/dist/secrets.d.ts +152 -0
- package/dist/secrets.js +544 -0
- package/dist/secrets.js.map +1 -0
- package/package.json +67 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.cjs","names":["copyFailure","copyFailure"],"sources":["../src/files/detect.ts","../src/files/name.ts","../src/files/types.ts","../src/files/inspect.ts","../src/files/accept.ts","../src/files/collect.ts"],"sourcesContent":["import type { DetectedType, FileFamily } from './types';\n\n/** How many leading bytes {@link detectFileType} reads: enough for every signature and a text sniff. */\nexport const FILE_SNIFF_BYTES = 8192;\n\nconst type = (mime: string, family: FileFamily, extensions: readonly string[], parent: string | null = null): DetectedType =>\n Object.freeze({ mime, family, extensions: Object.freeze(extensions), parent });\n\nconst ZIP = 'application/zip';\nconst TEXT = 'text/plain';\nconst OLE = 'application/x-ole-storage';\n\n/** Every type this module recognises, by MIME type. */\nexport const FILE_TYPES = {\n pdf: type('application/pdf', 'document', ['pdf']),\n png: type('image/png', 'image', ['png', 'apng']),\n jpeg: type('image/jpeg', 'image', ['jpg', 'jpeg', 'jpe', 'jfif']),\n gif: type('image/gif', 'image', ['gif']),\n webp: type('image/webp', 'image', ['webp']),\n avif: type('image/avif', 'image', ['avif']),\n heic: type('image/heic', 'image', ['heic', 'heif']),\n bmp: type('image/bmp', 'image', ['bmp', 'dib']),\n ico: type('image/x-icon', 'image', ['ico', 'cur']),\n tiff: type('image/tiff', 'image', ['tif', 'tiff', 'dng', 'cr2', 'nef', 'arw']),\n psd: type('image/vnd.adobe.photoshop', 'image', ['psd']),\n svg: type('image/svg+xml', 'image', ['svg', 'svgz'], TEXT),\n mp3: type('audio/mpeg', 'audio', ['mp3']),\n wav: type('audio/wav', 'audio', ['wav']),\n flac: type('audio/flac', 'audio', ['flac']),\n ogg: type('audio/ogg', 'audio', ['ogg', 'oga', 'ogv', 'opus', 'spx']),\n m4a: type('audio/mp4', 'audio', ['m4a', 'm4b'], 'video/mp4'),\n mp4: type('video/mp4', 'video', ['mp4', 'm4v', 'm4a', 'mov']),\n mov: type('video/quicktime', 'video', ['mov', 'qt'], 'video/mp4'),\n threegp: type('video/3gpp', 'video', ['3gp', '3g2'], 'video/mp4'),\n webm: type('video/webm', 'video', ['webm', 'weba']),\n mkv: type('video/x-matroska', 'video', ['mkv', 'mka', 'webm']),\n avi: type('video/x-msvideo', 'video', ['avi']),\n zip: type(ZIP, 'archive', ['zip']),\n docx: type('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'document', ['docx', 'docm', 'dotx', 'dotm'], ZIP),\n xlsx: type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'document', ['xlsx', 'xlsm', 'xltx', 'xltm'], ZIP),\n pptx: type('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'document', ['pptx', 'pptm', 'potx', 'potm', 'ppsx', 'ppsm'], ZIP),\n odt: type('application/vnd.oasis.opendocument.text', 'document', ['odt'], ZIP),\n ods: type('application/vnd.oasis.opendocument.spreadsheet', 'document', ['ods'], ZIP),\n odp: type('application/vnd.oasis.opendocument.presentation', 'document', ['odp'], ZIP),\n epub: type('application/epub+zip', 'document', ['epub'], ZIP),\n jar: type('application/java-archive', 'executable', ['jar', 'war', 'ear'], ZIP),\n apk: type('application/vnd.android.package-archive', 'executable', ['apk', 'aab'], ZIP),\n ole: type(OLE, 'document', ['doc', 'xls', 'ppt', 'msg', 'msi', 'dot', 'xlt', 'pps']),\n rtf: type('application/rtf', 'document', ['rtf'], TEXT),\n gzip: type('application/gzip', 'archive', ['gz', 'tgz']),\n bzip2: type('application/x-bzip2', 'archive', ['bz2', 'tbz2']),\n xz: type('application/x-xz', 'archive', ['xz', 'txz']),\n zstd: type('application/zstd', 'archive', ['zst']),\n sevenZip: type('application/x-7z-compressed', 'archive', ['7z']),\n rar: type('application/vnd.rar', 'archive', ['rar']),\n tar: type('application/x-tar', 'archive', ['tar']),\n sqlite: type('application/vnd.sqlite3', 'data', ['sqlite', 'sqlite3']),\n woff: type('font/woff', 'font', ['woff']),\n woff2: type('font/woff2', 'font', ['woff2']),\n otf: type('font/otf', 'font', ['otf']),\n ttf: type('font/ttf', 'font', ['ttf', 'ttc']),\n exe: type('application/vnd.microsoft.portable-executable', 'executable', ['exe', 'dll', 'sys', 'scr', 'com', 'cpl', 'ocx', 'efi']),\n elf: type('application/x-elf', 'executable', ['so', 'run', 'elf']),\n macho: type('application/x-mach-binary', 'executable', ['dylib', 'bundle']),\n wasm: type('application/wasm', 'executable', ['wasm']),\n shortcut: type('application/x-ms-shortcut', 'executable', ['lnk']),\n script: type('text/x-shellscript', 'executable', ['sh', 'bash', 'zsh', 'command', 'py', 'pl', 'rb'], TEXT),\n html: type('text/html', 'text', ['html', 'htm', 'xhtml', 'xht', 'shtml', 'mht', 'mhtml'], TEXT),\n xml: type('application/xml', 'text', ['xml', 'xsl', 'xslt', 'rss', 'atom', 'kml', 'gpx'], TEXT),\n json: type('application/json', 'text', ['json', 'geojson', 'jsonld', 'webmanifest', 'map'], TEXT),\n text: type(TEXT, 'text', ['txt']),\n} as const;\n\n/** Bounds-checked reads: past the end is never a match. */\nclass Head {\n readonly bytes: Uint8Array;\n constructor(bytes: Uint8Array) {\n this.bytes = bytes;\n }\n at(index: number): number {\n return index < this.bytes.length ? (this.bytes[index] as number) : -1;\n }\n is(offset: number, ...values: readonly number[]): boolean {\n return values.every((value, index) => this.at(offset + index) === value);\n }\n ascii(offset: number, length: number): string {\n let out = '';\n for (let index = offset; index < offset + length && index < this.bytes.length; index += 1) out += String.fromCharCode(this.bytes[index] as number);\n return out;\n }\n u16le(offset: number): number {\n return this.at(offset) + (this.at(offset + 1) << 8);\n }\n u32le(offset: number): number {\n return (this.at(offset) | (this.at(offset + 1) << 8) | (this.at(offset + 2) << 16) | (this.at(offset + 3) << 24)) >>> 0;\n }\n}\n\n/** ISO base media (MP4, MOV, HEIC, AVIF, 3GP): `ftyp` with its major brand. */\nfunction isoMedia(head: Head): DetectedType | null {\n if (head.ascii(4, 4) !== 'ftyp') return null;\n const brand = head.ascii(8, 4);\n if (brand === 'avif' || brand === 'avis') return FILE_TYPES.avif;\n if (['heic', 'heix', 'heim', 'heis', 'hevc', 'hevx', 'mif1', 'msf1'].includes(brand)) return FILE_TYPES.heic;\n if (brand === 'qt ') return FILE_TYPES.mov;\n if (brand.startsWith('M4A') || brand.startsWith('M4B')) return FILE_TYPES.m4a;\n if (brand.startsWith('3g')) return FILE_TYPES.threegp;\n return FILE_TYPES.mp4;\n}\n\n/** RIFF containers: WebP, WAV, AVI. */\nfunction riff(head: Head): DetectedType | null {\n if (head.ascii(0, 4) !== 'RIFF') return null;\n const form = head.ascii(8, 4);\n if (form === 'WEBP') return FILE_TYPES.webp;\n if (form === 'WAVE') return FILE_TYPES.wav;\n if (form === 'AVI ') return FILE_TYPES.avi;\n return null;\n}\n\n/** A ZIP, and what it packages: Office, OpenDocument, EPUB, Java and Android archives. */\nfunction zip(head: Head): { readonly type: DetectedType; readonly macros: boolean } | null {\n if (!head.is(0, 0x50, 0x4b) || !(head.is(2, 0x03, 0x04) || head.is(2, 0x05, 0x06) || head.is(2, 0x07, 0x08))) return null;\n // OpenDocument and EPUB store their type first, uncompressed, in an entry named `mimetype`.\n if (head.ascii(30, 8) === 'mimetype') {\n const declared = head.ascii(38, head.u32le(18) > 0 && head.u32le(18) < 100 ? head.u32le(18) : 80);\n for (const candidate of [FILE_TYPES.epub, FILE_TYPES.odt, FILE_TYPES.ods, FILE_TYPES.odp]) {\n if (declared.startsWith(candidate.mime)) return { type: candidate, macros: false };\n }\n }\n // Entry names are stored as plain text in each local header: scan the head for them.\n const names = head.ascii(0, head.bytes.length);\n const macros = names.includes('vbaProject.bin');\n if (names.includes('AndroidManifest.xml') || names.includes('classes.dex')) return { type: FILE_TYPES.apk, macros };\n if (names.includes('META-INF/MANIFEST.MF')) return { type: FILE_TYPES.jar, macros };\n if (names.includes('word/')) return { type: FILE_TYPES.docx, macros };\n if (names.includes('xl/')) return { type: FILE_TYPES.xlsx, macros };\n if (names.includes('ppt/')) return { type: FILE_TYPES.pptx, macros };\n return { type: FILE_TYPES.zip, macros };\n}\n\n/** Binary formats, recognised by their signatures. */\nfunction binary(head: Head): DetectedType | null {\n if (head.ascii(0, 5) === '%PDF-') return FILE_TYPES.pdf;\n if (head.is(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return FILE_TYPES.png;\n if (head.is(0, 0xff, 0xd8, 0xff)) return FILE_TYPES.jpeg;\n if (head.ascii(0, 6) === 'GIF87a' || head.ascii(0, 6) === 'GIF89a') return FILE_TYPES.gif;\n if (head.ascii(0, 2) === 'BM' && [12, 40, 52, 56, 64, 108, 124].includes(head.u32le(14))) return FILE_TYPES.bmp;\n if (head.is(0, 0, 0, 1, 0) || head.is(0, 0, 0, 2, 0)) {\n // ICO and CUR: a count of images, each 16 bytes, then the first image's offset past the directory.\n const count = head.u16le(4);\n if (count > 0 && count <= 256 && head.at(9) === 0) return FILE_TYPES.ico;\n }\n if (head.is(0, 0x49, 0x49, 0x2a, 0x00) || head.is(0, 0x4d, 0x4d, 0x00, 0x2a)) return FILE_TYPES.tiff;\n if (head.ascii(0, 4) === '8BPS') return FILE_TYPES.psd;\n const media = isoMedia(head) ?? riff(head);\n if (media) return media;\n if (head.ascii(0, 3) === 'ID3' || (head.at(0) === 0xff && [0xfb, 0xf3, 0xf2].includes(head.at(1)))) return FILE_TYPES.mp3;\n if (head.ascii(0, 4) === 'fLaC') return FILE_TYPES.flac;\n if (head.ascii(0, 4) === 'OggS') return FILE_TYPES.ogg;\n if (head.is(0, 0x1a, 0x45, 0xdf, 0xa3)) return head.ascii(0, 64).includes('webm') ? FILE_TYPES.webm : FILE_TYPES.mkv;\n if (head.is(0, 0x1f, 0x8b)) return FILE_TYPES.gzip;\n if (head.ascii(0, 3) === 'BZh') return FILE_TYPES.bzip2;\n if (head.is(0, 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00)) return FILE_TYPES.xz;\n if (head.is(0, 0x28, 0xb5, 0x2f, 0xfd)) return FILE_TYPES.zstd;\n if (head.is(0, 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c)) return FILE_TYPES.sevenZip;\n if (head.is(0, 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07)) return FILE_TYPES.rar;\n if (head.ascii(257, 5) === 'ustar') return FILE_TYPES.tar;\n if (head.is(0, 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1)) return FILE_TYPES.ole;\n if (head.ascii(0, 5) === '{\\\\rtf') return FILE_TYPES.rtf;\n if (head.ascii(0, 15) === 'SQLite format 3' && head.at(15) === 0) return FILE_TYPES.sqlite;\n if (head.ascii(0, 4) === 'wOFF') return FILE_TYPES.woff;\n if (head.ascii(0, 4) === 'wOF2') return FILE_TYPES.woff2;\n if (head.ascii(0, 4) === 'OTTO') return FILE_TYPES.otf;\n if (head.is(0, 0x00, 0x01, 0x00, 0x00, 0x00) || head.ascii(0, 4) === 'true' || head.ascii(0, 4) === 'ttcf') return FILE_TYPES.ttf;\n if (head.ascii(0, 2) === 'MZ') return FILE_TYPES.exe;\n if (head.is(0, 0x7f, 0x45, 0x4c, 0x46)) return FILE_TYPES.elf;\n if ([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xcafebabe, 0xbebafeca].includes(head.u32le(0))) return FILE_TYPES.macho;\n if (head.is(0, 0x00, 0x61, 0x73, 0x6d)) return FILE_TYPES.wasm;\n if (head.is(0, 0x4c, 0x00, 0x00, 0x00, 0x01, 0x14, 0x02, 0x00)) return FILE_TYPES.shortcut;\n return null;\n}\n\n/** UTF-8 (valid, with no NUL), or UTF-16 with its byte order mark: the bytes are text. */\nfunction decodeText(bytes: Uint8Array, complete: boolean): string | null {\n if (bytes.length >= 2 && ((bytes[0] === 0xff && bytes[1] === 0xfe) || (bytes[0] === 0xfe && bytes[1] === 0xff))) {\n return new TextDecoder(bytes[0] === 0xff ? 'utf-16le' : 'utf-16be').decode(bytes.subarray(2));\n }\n if (bytes.includes(0)) return null;\n try {\n // `stream` leaves a character cut at the end of the head undecoded, instead of an error.\n return new TextDecoder('utf-8', { fatal: true }).decode(bytes, { stream: !complete });\n } catch {\n return null;\n }\n}\n\n/** Elements that start an HTML document. Case-insensitive, though it is given lowercase text. */\nconst HTML_START = /^<(?:!doctype\\s+html|html|head|body|script|iframe|frame|object|embed|meta|title|link|style|base|form|div|p|a|img|table)[\\s/>]/i;\n\n/** Text formats, recognised from their start. */\nfunction textType(text: string, complete: boolean): DetectedType {\n const start = text.replace(/^\\uFEFF/, '').trimStart();\n const lower = start.slice(0, 1024).toLowerCase();\n if (start.startsWith('#!')) return FILE_TYPES.script;\n if (lower.startsWith('{\\\\rtf')) return FILE_TYPES.rtf;\n if (lower.startsWith('<')) {\n // Past an XML declaration, comments and a doctype: the first element decides.\n const body = lower.replace(/^(?:<\\?[\\s\\S]*?\\?>|<!--[\\s\\S]*?-->|<!doctype\\s+(?!html)[^>]*>|\\s+)*/, '');\n if (body.startsWith('<svg')) return FILE_TYPES.svg;\n if (HTML_START.test(body)) return FILE_TYPES.html;\n return lower.startsWith('<?xml') || /^<[a-z_][\\w.:-]*[\\s/>]/.test(body) ? FILE_TYPES.xml : FILE_TYPES.text;\n }\n if (complete && (start.startsWith('{') || start.startsWith('['))) {\n try {\n JSON.parse(start);\n return FILE_TYPES.json;\n } catch {\n return FILE_TYPES.text;\n }\n }\n return FILE_TYPES.text;\n}\n\nexport interface Detection {\n readonly type: DetectedType | null;\n /** A ZIP-based Office file holding a VBA project. */\n readonly macros: boolean;\n /** Runs script when a browser opens it: HTML, SVG, or XML with XHTML, a script or a stylesheet. */\n readonly active: boolean;\n}\n\nconst ACTIVE_XML = /<script|<\\?xml-stylesheet|xmlns(?::[\\w.-]+)?\\s*=\\s*[\"']http:\\/\\/www\\.w3\\.org\\/1999\\/xhtml/i;\n\n/**\n * What `bytes` (the start of a file, {@link FILE_SNIFF_BYTES} or all of it) are.\n * `complete` says whether they are the whole file, which some text formats need (JSON).\n */\nexport function detect(bytes: Uint8Array, complete: boolean): Detection {\n const head = new Head(bytes);\n const packaged = zip(head);\n if (packaged) return { type: packaged.type, macros: packaged.macros, active: false };\n const found = binary(head);\n if (found) return { type: found, macros: false, active: false };\n const text = bytes.length === 0 ? null : decodeText(bytes, complete);\n if (text === null) return { type: null, macros: false, active: false };\n const kind = textType(text, complete);\n const active = kind === FILE_TYPES.html || kind === FILE_TYPES.svg || (kind === FILE_TYPES.xml && ACTIVE_XML.test(text));\n return { type: kind, macros: false, active };\n}\n\n/**\n * The type of a file's content, from its leading bytes: never from its name or claimed type.\n * Reads at most {@link FILE_SNIFF_BYTES}. `null` when the content is not a recognised type.\n */\nexport function detectFileType(bytes: Uint8Array, options: { readonly complete?: boolean } = {}): DetectedType | null {\n return detect(bytes.subarray(0, FILE_SNIFF_BYTES), options.complete ?? bytes.length <= FILE_SNIFF_BYTES).type;\n}\n","/** File names: making them safe to show and store, and what they say about the file. */\n\n/**\n * Extensions the operating system runs, or mounts, when the file is opened: Windows, macOS\n * and Linux programs, scripts and installers, shortcuts, and disk images (which can carry\n * programs past download warnings).\n */\nexport const EXECUTABLE_EXTENSIONS: ReadonlySet<string> = /* @__PURE__ */ new Set(\n (\n 'exe com scr pif bat cmd ps1 ps1xml ps2 psc1 psm1 psd1 vb vbs vbe js jse mjs cjs ws wsf wsc wsh hta msi msp mst msc ' +\n 'dll ocx sys cpl drv efi lnk url scf inf reg appref-ms application gadget xbap jar war ear class apk aab xapk ipa ' +\n 'app command tool sh bash zsh csh ksh fish run py pyc pyw pl rb php elf so dylib bundle deb rpm pkg mpkg dmg iso img vhd vhdx ' +\n 'appx appxbundle msix msixbundle wasm settingcontent-ms library-ms search-ms chm hlp'\n ).split(' '),\n);\n\n/** Extensions of documents, images and media: the decoy in front of an executable one (`invoice.pdf.exe`). */\nconst DECOY_EXTENSIONS: ReadonlySet<string> = /* @__PURE__ */ new Set(\n (\n 'pdf doc docx xls xlsx ppt pptx odt ods odp rtf txt csv md jpg jpeg png gif webp heic bmp tif tiff svg ' +\n 'mp3 mp4 mov avi wav m4a zip rar 7z html htm eml msg'\n ).split(' '),\n);\n\n/** Extensions of Office files that can hold macros. */\nexport const MACRO_EXTENSIONS: ReadonlySet<string> = /* @__PURE__ */ new Set(['docm', 'dotm', 'xlsm', 'xltm', 'xlam', 'pptm', 'potm', 'ppsm', 'ppam', 'sldm']);\n\n/** Extensions of active content: it runs script when a browser opens it from your origin. */\nexport const ACTIVE_EXTENSIONS: ReadonlySet<string> = /* @__PURE__ */ new Set(['html', 'htm', 'xhtml', 'xht', 'shtml', 'mht', 'mhtml', 'svg', 'svgz']);\n\n/**\n * Bidirectional controls, invisible and control characters, and other characters that make\n * a name display as something else, or break where it is stored.\n */\nconst HIDDEN_SOURCE = String.raw`[\\u0000-\\u001f\\u007f-\\u009f\\u00AD\\u061C\\u115F\\u1160\\u17B4\\u17B5\\u180B-\\u180F\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u206F\\u3164\\uFE00-\\uFE0F\\uFEFF\\uFFA0\\uFFF0-\\uFFFB]|[\\u{e0000}-\\u{e0fff}]`;\n// Variation selectors and other combining characters are matched one by one, on purpose.\n// eslint-disable-next-line no-misleading-character-class\nconst HIDDEN = /* @__PURE__ */ new RegExp(HIDDEN_SOURCE, 'u');\n// eslint-disable-next-line no-misleading-character-class\nconst HIDDEN_ALL = /* @__PURE__ */ new RegExp(HIDDEN_SOURCE, 'gu');\n\n/** Whether `name` holds characters that hide or reorder what it shows. */\nexport function hasHiddenCharacters(name: string): boolean {\n return HIDDEN.test(name);\n}\n\n/** The last extension of `name`, lowercase, without the dot; `null` for none (`README`, `.env`). */\nexport function extensionOf(name: string): string | null {\n const base = name.slice(Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\\\')) + 1).replace(/[\\s.]+$/u, '');\n const dot = base.lastIndexOf('.');\n if (dot <= 0) return null;\n // Not empty: trailing dots and whitespace are already gone.\n return base.slice(dot + 1).trim().toLowerCase();\n}\n\n/**\n * A document or image extension followed by an executable one, as in `invoice.pdf.exe`, or\n * an executable extension pushed out of view by a run of spaces (`invoice.pdf .exe`).\n */\nexport function hasDoubleExtension(name: string): boolean {\n const cleaned = name.replace(HIDDEN_ALL, '');\n const last = extensionOf(cleaned);\n if (last === null || !EXECUTABLE_EXTENSIONS.has(last)) return false;\n const rest = cleaned.slice(0, cleaned.toLowerCase().lastIndexOf(`.${last}`));\n if (/\\s{3,}$/u.test(rest)) return true;\n const previous = extensionOf(rest);\n return previous !== null && DECOY_EXTENSIONS.has(previous);\n}\n\nconst WINDOWS_RESERVED = /^(?:con|prn|aux|nul|com[0-9\\u00B9\\u00B2\\u00B3]|lpt[0-9\\u00B9\\u00B2\\u00B3]|conin\\$|conout\\$)$/i;\nconst encoder = /* @__PURE__ */ new TextEncoder();\n\n/** Cuts `text` to at most `bytes` UTF-8 bytes, never inside a character. */\nfunction cutToBytes(text: string, bytes: number): string {\n let out = '';\n let used = 0;\n for (const char of text) {\n const size = encoder.encode(char).length;\n if (used + size > bytes) break;\n out += char;\n used += size;\n }\n return out;\n}\n\nexport interface SafeFileNameOptions {\n /** Longest name, in UTF-8 bytes (what file systems limit). Default 255. The extension is kept. */\n readonly maxBytes?: number;\n /** Put in place of characters that can't be in a file name. Default `_`. */\n readonly replacement?: string;\n /** The name to use when nothing usable is left. Default `file`. */\n readonly fallback?: string;\n}\n\n/** A replacement that can itself be in a file name (up to 4 characters), or `_`. */\nconst safeReplacement = (value: string): string => (/^[^<>:\"/\\\\|?*\\s.]{0,4}$/u.test(value) && !hasHiddenCharacters(value) ? value : '_');\n\n/**\n * `name` made safe to show and to store on any operating system:\n *\n * - only the last path segment is kept, so `../../etc/passwd` becomes `passwd`;\n * - bidirectional controls, invisible and control characters are removed (tabs and line breaks become spaces);\n * - characters Windows, macOS or Linux reject (`<>:\"/\\|?*`) become `replacement`;\n * - runs of whitespace become one space, and leading dots and spaces and trailing dots and\n * spaces are removed (no hidden files, nothing Windows would change);\n * - Windows device names (`CON`, `NUL`, `COM1`, ...) are prefixed with `replacement`;\n * - the result is at most `maxBytes` long in UTF-8, keeping the extension; Unicode is NFC.\n *\n * Never empty: `fallback` is used when nothing is left. Idempotent.\n */\nexport function safeFileName(name: string, options: SafeFileNameOptions = {}): string {\n const replacement = safeReplacement(options.replacement ?? '_');\n const fallback = options.fallback ?? 'file';\n const maxBytes = Math.max(16, Math.floor(options.maxBytes ?? 255));\n // Line breaks and tabs separate words: they become spaces, before other control characters go.\n // Composed (NFC) after the hidden characters go: removing one can bring a letter and its accent together.\n let safe = name.replace(/[\\t\\n\\v\\f\\r]/gu, ' ').replace(HIDDEN_ALL, '').normalize('NFC');\n safe = safe.slice(Math.max(safe.lastIndexOf('/'), safe.lastIndexOf('\\\\')) + 1);\n safe = safe\n .replace(/[<>:\"|?*]/gu, replacement)\n .replace(/\\s+/gu, ' ')\n .replace(/^[\\s.]+/u, '')\n .replace(/[\\s.]+$/u, '');\n if (safe === '') return fallback;\n const prefix = replacement === '' ? '_' : replacement;\n const reserved = (text: string): boolean => WINDOWS_RESERVED.test((text.includes('.') ? text.slice(0, text.indexOf('.')) : text).trim());\n if (reserved(safe)) safe = `${prefix}${safe}`;\n if (encoder.encode(safe).length <= maxBytes) return safe;\n const extension = extensionOf(safe);\n // The extension is kept when it is short, leaving room for a name (and a prefix) in front of it.\n const kept = extension === null ? '' : `.${extension}`;\n const suffix = kept !== '' && encoder.encode(kept).length <= Math.min(17, maxBytes - 8) ? kept : '';\n const budget = maxBytes - encoder.encode(suffix).length;\n // Never empty: the budget fits any character, and the first is not a dot or a space.\n const cut = (bytes: number): string => cutToBytes(safe.slice(0, safe.length - suffix.length), bytes).replace(/[\\s.]+$/u, '');\n const result = `${cut(budget)}${suffix}`;\n // Cutting can leave a device name (`com1a.txt` cut to `com1.txt`): prefix it, within the budget.\n return reserved(result) ? `${prefix}${cut(budget - encoder.encode(prefix).length)}${suffix}` : result;\n}\n","/** What a file is for, by its content. */\nexport type FileFamily = 'image' | 'audio' | 'video' | 'document' | 'archive' | 'text' | 'font' | 'executable' | 'data';\n\n/** A file type recognised from the file's bytes, never from its name or its claimed MIME type. */\nexport interface DetectedType {\n /** The MIME type to store and serve it as, e.g. `application/pdf`. */\n readonly mime: string;\n readonly family: FileFamily;\n /** Extensions this type is saved with, lowercase and without the dot; the first is the usual one. */\n readonly extensions: readonly string[];\n /**\n * The container it is a kind of: `application/zip` for a Word document, `text/plain` for\n * JSON. A file named for the container is not a mismatch (`.zip` holding a `.docx`).\n */\n readonly parent: string | null;\n}\n\n/**\n * Why a file may be unsafe to accept. Each is reported by {@link inspectFile}; the ones in\n * `block` (all of them by default) make {@link acceptFiles} reject the file.\n *\n * - `executable`: a program or script, by content (`MZ`, ELF, Mach-O, `#!`, a shortcut) or\n * by a name the operating system runs (`.exe`, `.bat`, `.ps1`, `.js`, `.jar`, `.iso`, ...).\n * - `active-content`: runs script when opened in a browser from your origin: HTML, SVG, XHTML.\n * - `macros`: an Office file that can hold macros (`.docm`, `.xlsm`, or a `vbaProject.bin`).\n * - `type-mismatch`: the content is not what the extension says (`report.pdf` holding HTML).\n * - `double-extension`: a document or image extension hiding an executable one (`invoice.pdf.exe`).\n * - `hidden-characters`: the name holds bidirectional controls, invisible or control characters,\n * which can make `invoice\\u202Egpj.exe` display as `invoiceexe.jpg`.\n * - `empty`: the file has no bytes (a folder dragged where folders are not read, or a failed save).\n */\nexport type FileRisk = 'executable' | 'active-content' | 'macros' | 'type-mismatch' | 'double-extension' | 'hidden-characters' | 'empty';\n\n/** Every risk, in a stable order. */\nexport const FILE_RISKS: readonly FileRisk[] = Object.freeze(['executable', 'active-content', 'macros', 'type-mismatch', 'double-extension', 'hidden-characters', 'empty']);\n\nexport interface FileInspection {\n /** The name as given, which may be unsafe to display or store. */\n readonly name: string;\n /** The name made safe to show and store: see {@link safeFileName}. */\n readonly safeName: string;\n /** The last extension, lowercase and without the dot; `null` when there is none. */\n readonly extension: string | null;\n readonly size: number;\n /** The MIME type the browser or caller claimed. Never trusted: kept for reference. */\n readonly declaredType: string;\n /** What the bytes are, or `null` when they are not a type this module recognises. */\n readonly detected: DetectedType | null;\n /**\n * The type to store and serve the file as: the detected one, or `application/octet-stream`\n * when the content is not recognised (never the claimed type).\n */\n readonly type: string;\n /** Whether the content contradicts the extension. Also listed in `risks`. */\n readonly mismatch: boolean;\n /** In the order of {@link FILE_RISKS}. */\n readonly risks: readonly FileRisk[];\n}\n","import { copyFailure } from '../core/errors';\nimport { FILE_SNIFF_BYTES, FILE_TYPES, detect } from './detect';\nimport { ACTIVE_EXTENSIONS, EXECUTABLE_EXTENSIONS, MACRO_EXTENSIONS, extensionOf, hasDoubleExtension, hasHiddenCharacters, safeFileName, type SafeFileNameOptions } from './name';\nimport { FILE_RISKS, type DetectedType, type FileInspection, type FileRisk } from './types';\n\n/** Content types that any text extension may hold (`.csv`, `.md`, `.log`, ...). */\nconst PLAIN_TEXT: ReadonlySet<string> = /* @__PURE__ */ new Set([FILE_TYPES.text.mime, FILE_TYPES.json.mime, FILE_TYPES.xml.mime]);\n\n/** Extensions of text formats this module doesn't tell apart: any plain text content fits them. */\nconst TEXT_EXTENSIONS: ReadonlySet<string> = /* @__PURE__ */ new Set(\n (\n 'txt text csv tsv md markdown mdx rst adoc org tex bib log ini cfg conf toml yaml yml env properties ics vcf vcard sql srt vtt sub ' +\n 'css scss sass less js mjs cjs jsx ts tsx mts cts vue svelte astro py rb pl php go rs java kt kts c h cc cpp hpp cs swift m ' +\n 'sh bash zsh bat cmd ps1 r lua dart scala clj ex exs erl hs ml fs diff patch gitignore editorconfig'\n ).split(' '),\n);\n\n/** MIME types of text formats known by their extension, for `accept` lists such as `text/csv`. */\nexport const TEXT_MIME_BY_EXTENSION: Readonly<Record<string, readonly string[]>> = {\n csv: ['text/csv'],\n tsv: ['text/tab-separated-values'],\n md: ['text/markdown'],\n markdown: ['text/markdown'],\n yaml: ['application/yaml', 'text/yaml'],\n yml: ['application/yaml', 'text/yaml'],\n ics: ['text/calendar'],\n vcf: ['text/vcard'],\n css: ['text/css'],\n js: ['text/javascript'],\n mjs: ['text/javascript'],\n vtt: ['text/vtt'],\n srt: ['application/x-subrip'],\n json: ['application/json'],\n xml: ['application/xml', 'text/xml'],\n};\n\nlet byExtension: ReadonlyMap<string, readonly DetectedType[]> | null = null;\n\n/** Every type saved with `extension`. Built on first use. */\nfunction typesFor(extension: string): readonly DetectedType[] {\n if (byExtension === null) {\n const map = new Map<string, DetectedType[]>();\n for (const type of Object.values(FILE_TYPES)) {\n for (const ext of type.extensions) map.set(ext, [...(map.get(ext) ?? []), type]);\n }\n byExtension = map;\n }\n return byExtension.get(extension) ?? [];\n}\n\n/** Whether `extension` is saved for text: a known text format, or a type that is text inside. */\nfunction isTextExtension(extension: string): boolean {\n return TEXT_EXTENSIONS.has(extension) || typesFor(extension).some((type) => type.parent === FILE_TYPES.text.mime || type === FILE_TYPES.text);\n}\n\n/**\n * Whether the content contradicts the extension. An unknown extension never does; a known one\n * does when the content is another type (a container and what it packages are the same family:\n * `.zip` and a Word document), or is not recognised at all.\n */\nexport function contradicts(extension: string | null, detected: DetectedType | null): boolean {\n if (extension === null) return false;\n const expected = typesFor(extension);\n const text = isTextExtension(extension);\n if (expected.length === 0 && !text) return false;\n if (detected === null) return true;\n // A container and what it packages are one family (`.zip` and a Word document); text is not a\n // container here: HTML and scripts are text, but a `.txt` holding one is not what it says.\n const related = (child: DetectedType, parent: DetectedType): boolean => child.parent === parent.mime && parent !== FILE_TYPES.text;\n if (expected.some((type) => type.mime === detected.mime || related(detected, type) || related(type, detected))) return false;\n return !(text && PLAIN_TEXT.has(detected.mime));\n}\n\n/** The type to store a file as: the detected one, made precise by the extension for plain text (`text/csv`). */\nfunction typeOf(detected: DetectedType | null, extension: string | null, mismatch: boolean): string {\n if (detected === null) return 'application/octet-stream';\n const named = extension === null || mismatch ? undefined : TEXT_MIME_BY_EXTENSION[extension]?.[0];\n return named !== undefined && PLAIN_TEXT.has(detected.mime) ? named : detected.mime;\n}\n\n/** An inspection of `bytes`, the start of a file (all of it when `complete`). */\nexport function inspectBytes(bytes: Uint8Array, name: string, declaredType: string, size: number, complete: boolean, names: SafeFileNameOptions = {}): FileInspection {\n const extension = extensionOf(name);\n const detection = detect(bytes, complete);\n const detected = detection.type;\n // An empty file is reported as `empty`: it has no content to contradict its name.\n const mismatch = size > 0 && contradicts(extension, detected);\n const found = new Set<FileRisk>();\n if (detected?.family === 'executable' || (extension !== null && EXECUTABLE_EXTENSIONS.has(extension))) found.add('executable');\n if (detection.active || (extension !== null && ACTIVE_EXTENSIONS.has(extension))) found.add('active-content');\n if (detection.macros || (extension !== null && MACRO_EXTENSIONS.has(extension))) found.add('macros');\n if (mismatch) found.add('type-mismatch');\n if (hasDoubleExtension(name)) found.add('double-extension');\n if (hasHiddenCharacters(name)) found.add('hidden-characters');\n if (size === 0) found.add('empty');\n return {\n name,\n safeName: safeFileName(name, names),\n extension,\n size,\n declaredType,\n detected,\n type: typeOf(detected, extension, mismatch),\n mismatch,\n risks: FILE_RISKS.filter((risk) => found.has(risk)),\n };\n}\n\nexport interface InspectFileOptions {\n /** The file's name. Default: `file.name`, for a `File`. */\n readonly name?: string;\n /** The type it claims. Default: `file.type`. Kept for reference only: never trusted. */\n readonly declaredType?: string;\n /** How {@link FileInspection.safeName} is made. */\n readonly names?: SafeFileNameOptions;\n}\n\n/** Reads the first `bytes` of `blob`. */\nexport async function readHead(blob: Blob, bytes: number): Promise<Uint8Array> {\n const candidate: unknown = blob; // Plain-JS callers can pass anything.\n if (typeof candidate !== 'object' || candidate === null || typeof (candidate as Partial<Blob>).slice !== 'function') {\n throw copyFailure('invalid-payload', 'Expected a Blob or File.');\n }\n return new Uint8Array(await blob.slice(0, bytes).arrayBuffer());\n}\n\n/**\n * What a file really is, and why it may be unsafe to accept: its type from its content (never\n * its name or claimed type), whether that contradicts its extension, and its risks.\n * Reads only the first {@link FILE_SNIFF_BYTES} bytes, so it is fast for any size. Server-safe.\n *\n * @throws {CopyFailure} `invalid-payload` when `file` is not a Blob.\n */\nexport async function inspectFile(file: Blob, options: InspectFileOptions = {}): Promise<FileInspection> {\n const head = await readHead(file, FILE_SNIFF_BYTES);\n const name = options.name ?? (file as Partial<File>).name ?? '';\n return inspectBytes(head, name, options.declaredType ?? file.type, file.size, file.size <= FILE_SNIFF_BYTES, options.names);\n}\n","import { TEXT_MIME_BY_EXTENSION } from './inspect';\nimport type { FileInspection } from './types';\n\n/** The tokens of an `accept` list, as in `<input type=\"file\" accept>`: `.pdf`, `image/*`, `text/csv`. Lowercase. */\nexport function parseAccept(accept: string | readonly string[]): readonly string[] {\n const list = typeof accept === 'string' ? accept.split(',') : accept;\n return list.map((token) => token.trim().toLowerCase()).filter((token) => /^(?:\\.[^\\s,/\\\\]+|\\*|\\*\\/\\*|[a-z0-9!#$&^_.+-]+\\/(?:\\*|[a-z0-9!#$&^_.+-]+))$/.test(token));\n}\n\n/**\n * Whether a file fits an `accept` list, judged by its content. An extension token (`.pdf`)\n * matches the name, when the content does not contradict it. A MIME token (`application/pdf`,\n * `image/*`) matches the detected type or its container; plain text also matches the type its\n * extension names (`text/csv` for `data.csv`). The claimed type is never used. An empty list\n * accepts everything.\n */\nexport function matchesAccept(inspection: FileInspection, accept: string | readonly string[]): boolean {\n const tokens = parseAccept(accept);\n if (tokens.length === 0) return true;\n const name = inspection.name.toLowerCase();\n const types = [inspection.type];\n if (inspection.detected?.parent) types.push(inspection.detected.parent);\n if (inspection.detected?.family === 'text' && !inspection.mismatch && inspection.extension !== null) {\n types.push(...(TEXT_MIME_BY_EXTENSION[inspection.extension] ?? []));\n }\n return tokens.some((token) => {\n if (token === '*' || token === '*/*') return true;\n if (token.startsWith('.')) return name.endsWith(token) && !inspection.mismatch;\n if (token.endsWith('/*')) return inspection.detected !== null && types.some((type) => type.startsWith(token.slice(0, -1)));\n return types.includes(token);\n });\n}\n","import { copyFailure } from '../core/errors';\nimport { matchesAccept } from './accept';\nimport { FILE_SNIFF_BYTES } from './detect';\nimport { inspectBytes, readHead } from './inspect';\nimport { safeFileName, type SafeFileNameOptions } from './name';\nimport { FILE_RISKS, type FileInspection, type FileRisk } from './types';\n\nexport const DEFAULT_MAX_FILES = 100;\nexport const DEFAULT_MAX_FILE_BYTES = 100 * 1024 * 1024;\nexport const DEFAULT_MAX_TOTAL_BYTES = 1024 * 1024 * 1024;\nexport const DEFAULT_MAX_FOLDER_DEPTH = 8;\n\n/**\n * Where files come from: a paste or drop event (DOM or React), its `DataTransfer`, a\n * `FileList` (`<input type=\"file\">`), or any list of Files and Blobs.\n */\nexport type FileSource =\n | DataTransfer\n | { readonly clipboardData: DataTransfer | null }\n | { readonly dataTransfer: DataTransfer | null }\n | Iterable<Blob>\n | ArrayLike<Blob>;\n\n/** Why {@link acceptFiles} turned a file (or a folder) away. */\nexport type FileRejectReason =\n /** It has a risk listed in `block`; `risks` says which. */\n | 'blocked'\n /** It does not fit `accept`. */\n | 'not-accepted'\n /** Larger than `maxFileBytes`. */\n | 'too-large'\n /** Accepting it would take the accepted files over `maxTotalBytes`. */\n | 'total-too-large'\n /** More than `maxFiles` files: this one and any after it were left out (`truncated`). */\n | 'too-many'\n /** A folder deeper than `maxDepth`: its contents were not read. `file` is `null`. */\n | 'too-deep'\n /** It (or, with `file: null`, a folder) could not be read: deleted, moved or blocked by the system. */\n | 'unreadable'\n /** The same bytes as a file accepted before it (only checked with `digest: true`). */\n | 'duplicate';\n\nexport interface AcceptedFile {\n /** The file as it came. Its `name` and `type` are not safe to use: see `upload`. */\n readonly file: Blob;\n /**\n * The file to upload or store: the same bytes, named `name`, typed as `type` (a `File`, where\n * the platform has one). Its type is the detected one, never the claimed one.\n */\n readonly upload: Blob;\n /** The safe name. */\n readonly name: string;\n /** Where it was in the dropped folders, as safe names joined with `/` (`photos/2024/a.jpg`); just `name` for a loose file. */\n readonly path: string;\n readonly size: number;\n /** The detected type, or `application/octet-stream`. */\n readonly type: string;\n readonly inspection: FileInspection;\n /** Lowercase hex SHA-256 of the content, with `digest: true`; otherwise `null`. */\n readonly sha256: string | null;\n}\n\nexport interface RejectedFile {\n /** The file; `null` for a folder (`too-deep`, `unreadable`) or a dropped file the system would not give (`unreadable`). */\n readonly file: Blob | null;\n /** Safe name of the file or folder. */\n readonly name: string;\n /** Safe path, as in {@link AcceptedFile.path}. */\n readonly path: string;\n readonly reason: FileRejectReason;\n /** The file's risks, when it was inspected (all of them, not only the blocked ones). */\n readonly risks: readonly FileRisk[];\n /** A sentence for people, naming the file by its safe name. */\n readonly message: string;\n}\n\nexport interface AcceptFilesResult {\n /** In the order they were found: the order of the drop, folders depth-first. */\n readonly accepted: readonly AcceptedFile[];\n readonly rejected: readonly RejectedFile[];\n /** Total size of `accepted`, in bytes. */\n readonly totalBytes: number;\n /** More files were dropped than `maxFiles`: folders were not read to the end. */\n readonly truncated: boolean;\n}\n\nexport interface AcceptFilesOptions {\n /** Types to accept, as in `<input accept>`: `\".pdf,image/*\"` or `['.csv', 'text/plain']`. Judged by content. Default: any. */\n readonly accept?: string | readonly string[];\n /** Risks that reject a file. Default: every one of {@link FILE_RISKS}. `[]` accepts risky files (their `inspection.risks` still say). */\n readonly block?: readonly FileRisk[];\n /** Most files to accept. Default 100. */\n readonly maxFiles?: number;\n /** Largest single file, in bytes. Default 100 MiB. */\n readonly maxFileBytes?: number;\n /** Largest total of the accepted files, in bytes. Default 1 GiB. */\n readonly maxTotalBytes?: number;\n /** Read dropped folders (and the folders in them). Default `true`. With `false`, a folder is an `empty` file. */\n readonly folders?: boolean;\n /** Deepest folder level read: 1 reads only the dropped folder's own files. Default 8. */\n readonly maxDepth?: number;\n /** Compute each file's SHA-256 (reading it whole) and reject repeated content as `duplicate`. Default `false`. */\n readonly digest?: boolean;\n /** How names are made safe. */\n readonly names?: SafeFileNameOptions;\n /** Stops reading; the promise then rejects with an `aborted` CopyFailure. */\n readonly signal?: AbortSignal;\n}\n\n/* ----------------------------------------------------------------- Folders */\n\n/** The parts of the File and Directory Entries API this module uses (`webkitGetAsEntry`). */\ninterface Entry {\n readonly isFile: boolean;\n readonly isDirectory: boolean;\n readonly name: string;\n}\ninterface FileEntry extends Entry {\n file(success: (file: File) => void, failure?: (error: unknown) => void): void;\n}\ninterface DirectoryEntry extends Entry {\n createReader(): { readEntries(success: (entries: Entry[]) => void, failure?: (error: unknown) => void): void };\n}\n\n/** A dropped item: a folder entry to walk, or a file. */\ntype Root = { readonly entry: Entry } | { readonly file: Blob };\n\nfunction readEntries(directory: DirectoryEntry): AsyncGenerator<Entry, void, undefined> {\n const reader = directory.createReader();\n return (async function* batches() {\n // Each call returns the next batch (100 in Chromium); an empty batch is the end.\n for (;;) {\n const batch = await new Promise<Entry[]>((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n if (batch.length === 0) return;\n yield* batch;\n }\n })();\n}\n\nconst entryFile = (entry: FileEntry): Promise<File> =>\n new Promise((resolve, reject) => {\n entry.file(resolve, reject);\n });\n\nfunction isDataTransfer(value: FileSource): value is DataTransfer {\n return 'files' in value && 'types' in value;\n}\n\n/**\n * The dropped items, read at once: a `DataTransfer` is emptied when its event ends, so this\n * runs before anything is awaited. Dropped files are taken as files (`getAsFile`), which every\n * engine gives; entries are used only to walk folders.\n */\nfunction roots(source: FileSource, folders: boolean): Root[] {\n const candidate = source as Partial<{ clipboardData: DataTransfer | null; dataTransfer: DataTransfer | null }>;\n const transfer = isDataTransfer(source) ? source : (candidate.dataTransfer ?? candidate.clipboardData);\n if (transfer === undefined) {\n const list = source as Iterable<Blob> | ArrayLike<Blob>;\n return Array.from(Symbol.iterator in Object(list) ? (list as Iterable<Blob>) : (list as ArrayLike<Blob>), (file) => ({ file }));\n }\n if (transfer === null) return [];\n const found: Root[] = [];\n // Old browsers have no `items`: their `files` are all there is.\n for (const item of Array.from((transfer.items as DataTransferItemList | undefined) ?? [])) {\n if (item.kind !== 'file') continue;\n // `webkitGetAsEntry` is in every current browser; older ones and tests may lack it.\n const getEntry = (item as { webkitGetAsEntry?: () => unknown }).webkitGetAsEntry;\n const entry = folders && getEntry ? (getEntry.call(item) as Entry | null) : null;\n if (entry?.isDirectory) {\n found.push({ entry });\n continue;\n }\n const file = item.getAsFile();\n if (file) found.push({ file });\n }\n return found.length > 0 ? found : Array.from(transfer.files, (file) => ({ file }));\n}\n\n/** A file found in the drop, with its safe path; or a folder or file entry that could not be read. */\ntype Found =\n | { readonly kind: 'file'; readonly file: Blob; readonly path: string; readonly name: string }\n | { readonly kind: 'skipped'; readonly reason: 'too-deep' | 'unreadable'; readonly path: string; readonly name: string };\n\nasync function* walk(\n roots: readonly Root[],\n maxDepth: number,\n names: SafeFileNameOptions,\n): AsyncGenerator<Found, void, undefined> {\n const safe = (name: string, fallback: string): string => safeFileName(name, { ...names, fallback });\n async function* visit(entry: Entry, parent: string, depth: number): AsyncGenerator<Found, void, undefined> {\n const name = safe(entry.name, entry.isDirectory ? 'folder' : 'file');\n const path = parent === '' ? name : `${parent}/${name}`;\n if (entry.isFile) {\n try {\n yield { kind: 'file', file: await entryFile(entry as FileEntry), path, name };\n } catch {\n yield { kind: 'skipped', reason: 'unreadable', path, name };\n }\n return;\n }\n if (!entry.isDirectory) return;\n if (depth >= maxDepth) {\n yield { kind: 'skipped', reason: 'too-deep', path, name };\n return;\n }\n try {\n for await (const child of readEntries(entry as DirectoryEntry)) yield* visit(child, path, depth + 1);\n } catch {\n yield { kind: 'skipped', reason: 'unreadable', path, name };\n }\n }\n for (const root of roots) {\n if ('entry' in root) {\n yield* visit(root.entry, '', 0);\n } else {\n const name = safe((root.file as Partial<File>).name ?? '', 'file');\n yield { kind: 'file', file: root.file, path: name, name };\n }\n }\n}\n\n/* ---------------------------------------------------------------- Messages */\n\nconst UNITS = ['bytes', 'KB', 'MB', 'GB', 'TB'] as const;\n\n/** `1048576` as `1 MB`. */\nexport function formatBytes(bytes: number): string {\n let value = bytes;\n let unit = 0;\n while (value >= 1024 && unit < UNITS.length - 1) {\n value /= 1024;\n unit += 1;\n }\n return `${String(unit === 0 ? value : Math.round(value * 10) / 10)} ${UNITS[unit] as string}`;\n}\n\nconst RISK_MESSAGES: Readonly<Record<FileRisk, (name: string) => string>> = {\n executable: (name) => `${name} is a program or script, which can't be added.`,\n 'active-content': (name) => `${name} is a web page or SVG that can run scripts, so it can't be added.`,\n macros: (name) => `${name} can contain macros, so it can't be added.`,\n 'type-mismatch': (name) => `${name} is not the type of file its name says.`,\n 'double-extension': (name) => `${name} hides its real type behind a second extension.`,\n 'hidden-characters': (name) => `${name} has hidden characters in its name.`,\n empty: (name) => `${name} is empty.`,\n};\n\n/* ------------------------------------------------------------------ Accept */\n\nasync function sha256(blob: Blob): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', await blob.arrayBuffer());\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n\nfunction positive(value: number | undefined, fallback: number, name: string): number {\n if (value === undefined) return fallback;\n if (!(value >= 0)) throw copyFailure('invalid-payload', `${name} must be a number of at least 0.`);\n return value;\n}\n\n/**\n * Takes the files from a paste, a drop (folders included), a file input or a list, and\n * decides for each whether it is safe and wanted: its type is read from its content, its\n * name made safe, and the limits applied. Nothing is uploaded or read whole (except with\n * `digest`): only each file's first 8 KiB.\n *\n * Call it from the event handler, before anything is awaited: a `DataTransfer` is emptied\n * when its event ends. Folders are read through `webkitGetAsEntry` (every current browser).\n *\n * ```ts\n * onDrop={(event) => {\n * event.preventDefault();\n * void acceptFiles(event, { accept: '.pdf,image/*', maxFileBytes: 20e6 }).then(({ accepted, rejected }) => { ... });\n * }}\n * ```\n *\n * @throws {CopyFailure} `aborted` when `signal` aborts; `unsupported` for `digest` without Web Crypto;\n * `invalid-payload` for a negative limit.\n */\nexport async function acceptFiles(source: FileSource, options: AcceptFilesOptions = {}): Promise<AcceptFilesResult> {\n const found = roots(source, options.folders ?? true);\n const maxFiles = positive(options.maxFiles, DEFAULT_MAX_FILES, 'maxFiles');\n const maxFileBytes = positive(options.maxFileBytes, DEFAULT_MAX_FILE_BYTES, 'maxFileBytes');\n const maxTotalBytes = positive(options.maxTotalBytes, DEFAULT_MAX_TOTAL_BYTES, 'maxTotalBytes');\n const maxDepth = positive(options.maxDepth, DEFAULT_MAX_FOLDER_DEPTH, 'maxDepth');\n const block = new Set(options.block ?? FILE_RISKS);\n const digest = options.digest === true;\n if (digest && (typeof crypto === 'undefined' || typeof crypto.subtle === 'undefined')) {\n throw copyFailure('unsupported', 'digest needs Web Crypto (crypto.subtle): a secure page, or Node.js 20+ (on 18, set globalThis.crypto to webcrypto from node:crypto).');\n }\n const signal = options.signal;\n const checkAborted = (): void => {\n if (signal?.aborted) throw copyFailure('aborted', 'Adding files was aborted.', signal.reason);\n };\n checkAborted();\n\n const accepted: AcceptedFile[] = [];\n const rejected: RejectedFile[] = [];\n const seen = new Map<string, string>();\n let totalBytes = 0;\n let count = 0;\n let truncated = false;\n const reject = (file: Blob | null, name: string, path: string, reason: FileRejectReason, message: string, risks: readonly FileRisk[] = []): void => {\n rejected.push({ file, name, path, reason, risks, message });\n };\n\n for await (const item of walk(found, maxDepth, options.names ?? {})) {\n checkAborted();\n if (item.kind === 'skipped') {\n reject(\n null,\n item.name,\n item.path,\n item.reason,\n item.reason === 'too-deep' ? `${item.path} was not read: it is more than ${String(maxDepth)} folders deep.` : `${item.path} could not be read.`,\n );\n continue;\n }\n const { file, name, path } = item;\n count += 1;\n if (count > maxFiles) {\n truncated = true;\n reject(file, name, path, 'too-many', `${name} and any files after it were not added: at most ${String(maxFiles)} files can be added at once.`);\n break;\n }\n if (file.size > maxFileBytes) {\n reject(file, name, path, 'too-large', `${name} is larger than ${formatBytes(maxFileBytes)}.`);\n continue;\n }\n let inspection: FileInspection;\n try {\n const head = await readHead(file, FILE_SNIFF_BYTES);\n inspection = inspectBytes(head, (file as Partial<File>).name ?? '', file.type, file.size, file.size <= FILE_SNIFF_BYTES, options.names);\n } catch {\n checkAborted();\n reject(file, name, path, 'unreadable', `${name} could not be read.`);\n continue;\n }\n checkAborted();\n const blocked = inspection.risks.find((risk) => block.has(risk));\n if (blocked !== undefined) {\n reject(file, name, path, 'blocked', RISK_MESSAGES[blocked](name), inspection.risks);\n continue;\n }\n if (options.accept !== undefined && !matchesAccept(inspection, options.accept)) {\n reject(file, name, path, 'not-accepted', `${name} is not a type of file that can be added here.`, inspection.risks);\n continue;\n }\n if (totalBytes + file.size > maxTotalBytes) {\n reject(file, name, path, 'total-too-large', `${name} was not added: the files together would be larger than ${formatBytes(maxTotalBytes)}.`, inspection.risks);\n continue;\n }\n let hash: string | null = null;\n if (digest) {\n try {\n hash = await sha256(file);\n } catch {\n checkAborted();\n reject(file, name, path, 'unreadable', `${name} could not be read.`, inspection.risks);\n continue;\n }\n checkAborted();\n const original = seen.get(hash);\n if (original !== undefined) {\n reject(file, name, path, 'duplicate', `${name} is the same file as ${original}.`, inspection.risks);\n continue;\n }\n seen.set(hash, path);\n }\n totalBytes += file.size;\n accepted.push({\n file,\n upload:\n typeof File === 'function'\n ? new File([file], name, { type: inspection.type, lastModified: (file as Partial<File>).lastModified ?? Date.now() })\n : new Blob([file], { type: inspection.type }),\n name,\n path,\n size: file.size,\n type: inspection.type,\n inspection,\n sha256: hash,\n });\n }\n return { accepted, rejected, totalBytes, truncated };\n}\n"],"mappings":";;;;;AAGA,MAAa,mBAAmB;AAEhC,MAAM,QAAQ,MAAc,QAAoB,YAA+B,SAAwB,SACrG,OAAO,OAAO;CAAE;CAAM;CAAQ,YAAY,OAAO,OAAO,UAAU;CAAG;AAAO,CAAC;AAE/E,MAAM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KAAK,0DAA0D,YAAY,aAAa,EAAE,IAAI,WAAW,KAAK;GAC7J;EACF;EACA,IAAI,OAAsB;EAC1B,IAAI,QAAQ;GACV,IAAI;IACF,OAAO,MAAM,OAAO,IAAI;GAC1B,QAAQ;IACN,aAAa;IACb,OAAO,MAAM,MAAM,MAAM,cAAc,GAAG,KAAK,sBAAsB,WAAW,KAAK;IACrF;GACF;GACA,aAAa;GACb,MAAM,WAAW,KAAK,IAAI,IAAI;GAC9B,IAAI,aAAa,KAAA,GAAW;IAC1B,OAAO,MAAM,MAAM,MAAM,aAAa,GAAG,KAAK,uBAAuB,SAAS,IAAI,WAAW,KAAK;IAClG;GACF;GACA,KAAK,IAAI,MAAM,IAAI;EACrB;EACA,cAAc,KAAK;EACnB,SAAS,KAAK;GACZ;GACA,QACE,OAAO,SAAS,aACZ,IAAI,KAAK,CAAC,IAAI,GAAG,MAAM;IAAE,MAAM,WAAW;IAAM,cAAe,KAAuB,gBAAgB,KAAK,IAAI;GAAE,CAAC,IAClH,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,WAAW,KAAK,CAAC;GAChD;GACA;GACA,MAAM,KAAK;GACX,MAAM,WAAW;GACjB;GACA,QAAQ;EACV,CAAC;CACH;CACA,OAAO;EAAE;EAAU;EAAU;EAAY;CAAU;AACrD"}
|
package/dist/files.d.cts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/files/types.d.ts
|
|
3
|
+
/** What a file is for, by its content. */
|
|
4
|
+
type FileFamily = 'image' | 'audio' | 'video' | 'document' | 'archive' | 'text' | 'font' | 'executable' | 'data';
|
|
5
|
+
/** A file type recognised from the file's bytes, never from its name or its claimed MIME type. */
|
|
6
|
+
interface DetectedType {
|
|
7
|
+
/** The MIME type to store and serve it as, e.g. `application/pdf`. */
|
|
8
|
+
readonly mime: string;
|
|
9
|
+
readonly family: FileFamily;
|
|
10
|
+
/** Extensions this type is saved with, lowercase and without the dot; the first is the usual one. */
|
|
11
|
+
readonly extensions: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* The container it is a kind of: `application/zip` for a Word document, `text/plain` for
|
|
14
|
+
* JSON. A file named for the container is not a mismatch (`.zip` holding a `.docx`).
|
|
15
|
+
*/
|
|
16
|
+
readonly parent: string | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Why a file may be unsafe to accept. Each is reported by {@link inspectFile}; the ones in
|
|
20
|
+
* `block` (all of them by default) make {@link acceptFiles} reject the file.
|
|
21
|
+
*
|
|
22
|
+
* - `executable`: a program or script, by content (`MZ`, ELF, Mach-O, `#!`, a shortcut) or
|
|
23
|
+
* by a name the operating system runs (`.exe`, `.bat`, `.ps1`, `.js`, `.jar`, `.iso`, ...).
|
|
24
|
+
* - `active-content`: runs script when opened in a browser from your origin: HTML, SVG, XHTML.
|
|
25
|
+
* - `macros`: an Office file that can hold macros (`.docm`, `.xlsm`, or a `vbaProject.bin`).
|
|
26
|
+
* - `type-mismatch`: the content is not what the extension says (`report.pdf` holding HTML).
|
|
27
|
+
* - `double-extension`: a document or image extension hiding an executable one (`invoice.pdf.exe`).
|
|
28
|
+
* - `hidden-characters`: the name holds bidirectional controls, invisible or control characters,
|
|
29
|
+
* which can make `invoice\u202Egpj.exe` display as `invoiceexe.jpg`.
|
|
30
|
+
* - `empty`: the file has no bytes (a folder dragged where folders are not read, or a failed save).
|
|
31
|
+
*/
|
|
32
|
+
type FileRisk = 'executable' | 'active-content' | 'macros' | 'type-mismatch' | 'double-extension' | 'hidden-characters' | 'empty';
|
|
33
|
+
/** Every risk, in a stable order. */
|
|
34
|
+
export declare const FILE_RISKS: readonly FileRisk[];
|
|
35
|
+
interface FileInspection {
|
|
36
|
+
/** The name as given, which may be unsafe to display or store. */
|
|
37
|
+
readonly name: string;
|
|
38
|
+
/** The name made safe to show and store: see {@link safeFileName}. */
|
|
39
|
+
readonly safeName: string;
|
|
40
|
+
/** The last extension, lowercase and without the dot; `null` when there is none. */
|
|
41
|
+
readonly extension: string | null;
|
|
42
|
+
readonly size: number;
|
|
43
|
+
/** The MIME type the browser or caller claimed. Never trusted: kept for reference. */
|
|
44
|
+
readonly declaredType: string;
|
|
45
|
+
/** What the bytes are, or `null` when they are not a type this module recognises. */
|
|
46
|
+
readonly detected: DetectedType | null;
|
|
47
|
+
/**
|
|
48
|
+
* The type to store and serve the file as: the detected one, or `application/octet-stream`
|
|
49
|
+
* when the content is not recognised (never the claimed type).
|
|
50
|
+
*/
|
|
51
|
+
readonly type: string;
|
|
52
|
+
/** Whether the content contradicts the extension. Also listed in `risks`. */
|
|
53
|
+
readonly mismatch: boolean;
|
|
54
|
+
/** In the order of {@link FILE_RISKS}. */
|
|
55
|
+
readonly risks: readonly FileRisk[];
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/files/accept.d.ts
|
|
59
|
+
/** The tokens of an `accept` list, as in `<input type="file" accept>`: `.pdf`, `image/*`, `text/csv`. Lowercase. */
|
|
60
|
+
export declare function parseAccept(accept: string | readonly string[]): readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* Whether a file fits an `accept` list, judged by its content. An extension token (`.pdf`)
|
|
63
|
+
* matches the name, when the content does not contradict it. A MIME token (`application/pdf`,
|
|
64
|
+
* `image/*`) matches the detected type or its container; plain text also matches the type its
|
|
65
|
+
* extension names (`text/csv` for `data.csv`). The claimed type is never used. An empty list
|
|
66
|
+
* accepts everything.
|
|
67
|
+
*/
|
|
68
|
+
export declare function matchesAccept(inspection: FileInspection, accept: string | readonly string[]): boolean;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/files/name.d.ts
|
|
71
|
+
/** File names: making them safe to show and store, and what they say about the file. */
|
|
72
|
+
/**
|
|
73
|
+
* Extensions the operating system runs, or mounts, when the file is opened: Windows, macOS
|
|
74
|
+
* and Linux programs, scripts and installers, shortcuts, and disk images (which can carry
|
|
75
|
+
* programs past download warnings).
|
|
76
|
+
*/
|
|
77
|
+
export declare const EXECUTABLE_EXTENSIONS: ReadonlySet<string>;
|
|
78
|
+
/** The last extension of `name`, lowercase, without the dot; `null` for none (`README`, `.env`). */
|
|
79
|
+
export declare function extensionOf(name: string): string | null;
|
|
80
|
+
interface SafeFileNameOptions {
|
|
81
|
+
/** Longest name, in UTF-8 bytes (what file systems limit). Default 255. The extension is kept. */
|
|
82
|
+
readonly maxBytes?: number;
|
|
83
|
+
/** Put in place of characters that can't be in a file name. Default `_`. */
|
|
84
|
+
readonly replacement?: string;
|
|
85
|
+
/** The name to use when nothing usable is left. Default `file`. */
|
|
86
|
+
readonly fallback?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* `name` made safe to show and to store on any operating system:
|
|
90
|
+
*
|
|
91
|
+
* - only the last path segment is kept, so `../../etc/passwd` becomes `passwd`;
|
|
92
|
+
* - bidirectional controls, invisible and control characters are removed (tabs and line breaks become spaces);
|
|
93
|
+
* - characters Windows, macOS or Linux reject (`<>:"/\|?*`) become `replacement`;
|
|
94
|
+
* - runs of whitespace become one space, and leading dots and spaces and trailing dots and
|
|
95
|
+
* spaces are removed (no hidden files, nothing Windows would change);
|
|
96
|
+
* - Windows device names (`CON`, `NUL`, `COM1`, ...) are prefixed with `replacement`;
|
|
97
|
+
* - the result is at most `maxBytes` long in UTF-8, keeping the extension; Unicode is NFC.
|
|
98
|
+
*
|
|
99
|
+
* Never empty: `fallback` is used when nothing is left. Idempotent.
|
|
100
|
+
*/
|
|
101
|
+
export declare function safeFileName(name: string, options?: SafeFileNameOptions): string;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/files/collect.d.ts
|
|
104
|
+
export declare const DEFAULT_MAX_FILES = 100;
|
|
105
|
+
export declare const DEFAULT_MAX_FILE_BYTES: number;
|
|
106
|
+
export declare const DEFAULT_MAX_TOTAL_BYTES: number;
|
|
107
|
+
export declare const DEFAULT_MAX_FOLDER_DEPTH = 8;
|
|
108
|
+
/**
|
|
109
|
+
* Where files come from: a paste or drop event (DOM or React), its `DataTransfer`, a
|
|
110
|
+
* `FileList` (`<input type="file">`), or any list of Files and Blobs.
|
|
111
|
+
*/
|
|
112
|
+
type FileSource = DataTransfer | {
|
|
113
|
+
readonly clipboardData: DataTransfer | null;
|
|
114
|
+
} | {
|
|
115
|
+
readonly dataTransfer: DataTransfer | null;
|
|
116
|
+
} | Iterable<Blob> | ArrayLike<Blob>;
|
|
117
|
+
/** Why {@link acceptFiles} turned a file (or a folder) away. */
|
|
118
|
+
type FileRejectReason =
|
|
119
|
+
/** It has a risk listed in `block`; `risks` says which. */
|
|
120
|
+
'blocked' |
|
|
121
|
+
/** It does not fit `accept`. */
|
|
122
|
+
'not-accepted' |
|
|
123
|
+
/** Larger than `maxFileBytes`. */
|
|
124
|
+
'too-large' |
|
|
125
|
+
/** Accepting it would take the accepted files over `maxTotalBytes`. */
|
|
126
|
+
'total-too-large' |
|
|
127
|
+
/** More than `maxFiles` files: this one and any after it were left out (`truncated`). */
|
|
128
|
+
'too-many' |
|
|
129
|
+
/** A folder deeper than `maxDepth`: its contents were not read. `file` is `null`. */
|
|
130
|
+
'too-deep' |
|
|
131
|
+
/** It (or, with `file: null`, a folder) could not be read: deleted, moved or blocked by the system. */
|
|
132
|
+
'unreadable' |
|
|
133
|
+
/** The same bytes as a file accepted before it (only checked with `digest: true`). */
|
|
134
|
+
'duplicate';
|
|
135
|
+
interface AcceptedFile {
|
|
136
|
+
/** The file as it came. Its `name` and `type` are not safe to use: see `upload`. */
|
|
137
|
+
readonly file: Blob;
|
|
138
|
+
/**
|
|
139
|
+
* The file to upload or store: the same bytes, named `name`, typed as `type` (a `File`, where
|
|
140
|
+
* the platform has one). Its type is the detected one, never the claimed one.
|
|
141
|
+
*/
|
|
142
|
+
readonly upload: Blob;
|
|
143
|
+
/** The safe name. */
|
|
144
|
+
readonly name: string;
|
|
145
|
+
/** Where it was in the dropped folders, as safe names joined with `/` (`photos/2024/a.jpg`); just `name` for a loose file. */
|
|
146
|
+
readonly path: string;
|
|
147
|
+
readonly size: number;
|
|
148
|
+
/** The detected type, or `application/octet-stream`. */
|
|
149
|
+
readonly type: string;
|
|
150
|
+
readonly inspection: FileInspection;
|
|
151
|
+
/** Lowercase hex SHA-256 of the content, with `digest: true`; otherwise `null`. */
|
|
152
|
+
readonly sha256: string | null;
|
|
153
|
+
}
|
|
154
|
+
interface RejectedFile {
|
|
155
|
+
/** The file; `null` for a folder (`too-deep`, `unreadable`) or a dropped file the system would not give (`unreadable`). */
|
|
156
|
+
readonly file: Blob | null;
|
|
157
|
+
/** Safe name of the file or folder. */
|
|
158
|
+
readonly name: string;
|
|
159
|
+
/** Safe path, as in {@link AcceptedFile.path}. */
|
|
160
|
+
readonly path: string;
|
|
161
|
+
readonly reason: FileRejectReason;
|
|
162
|
+
/** The file's risks, when it was inspected (all of them, not only the blocked ones). */
|
|
163
|
+
readonly risks: readonly FileRisk[];
|
|
164
|
+
/** A sentence for people, naming the file by its safe name. */
|
|
165
|
+
readonly message: string;
|
|
166
|
+
}
|
|
167
|
+
interface AcceptFilesResult {
|
|
168
|
+
/** In the order they were found: the order of the drop, folders depth-first. */
|
|
169
|
+
readonly accepted: readonly AcceptedFile[];
|
|
170
|
+
readonly rejected: readonly RejectedFile[];
|
|
171
|
+
/** Total size of `accepted`, in bytes. */
|
|
172
|
+
readonly totalBytes: number;
|
|
173
|
+
/** More files were dropped than `maxFiles`: folders were not read to the end. */
|
|
174
|
+
readonly truncated: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface AcceptFilesOptions {
|
|
177
|
+
/** Types to accept, as in `<input accept>`: `".pdf,image/*"` or `['.csv', 'text/plain']`. Judged by content. Default: any. */
|
|
178
|
+
readonly accept?: string | readonly string[];
|
|
179
|
+
/** Risks that reject a file. Default: every one of {@link FILE_RISKS}. `[]` accepts risky files (their `inspection.risks` still say). */
|
|
180
|
+
readonly block?: readonly FileRisk[];
|
|
181
|
+
/** Most files to accept. Default 100. */
|
|
182
|
+
readonly maxFiles?: number;
|
|
183
|
+
/** Largest single file, in bytes. Default 100 MiB. */
|
|
184
|
+
readonly maxFileBytes?: number;
|
|
185
|
+
/** Largest total of the accepted files, in bytes. Default 1 GiB. */
|
|
186
|
+
readonly maxTotalBytes?: number;
|
|
187
|
+
/** Read dropped folders (and the folders in them). Default `true`. With `false`, a folder is an `empty` file. */
|
|
188
|
+
readonly folders?: boolean;
|
|
189
|
+
/** Deepest folder level read: 1 reads only the dropped folder's own files. Default 8. */
|
|
190
|
+
readonly maxDepth?: number;
|
|
191
|
+
/** Compute each file's SHA-256 (reading it whole) and reject repeated content as `duplicate`. Default `false`. */
|
|
192
|
+
readonly digest?: boolean;
|
|
193
|
+
/** How names are made safe. */
|
|
194
|
+
readonly names?: SafeFileNameOptions;
|
|
195
|
+
/** Stops reading; the promise then rejects with an `aborted` CopyFailure. */
|
|
196
|
+
readonly signal?: AbortSignal;
|
|
197
|
+
}
|
|
198
|
+
/** `1048576` as `1 MB`. */
|
|
199
|
+
export declare function formatBytes(bytes: number): string;
|
|
200
|
+
/**
|
|
201
|
+
* Takes the files from a paste, a drop (folders included), a file input or a list, and
|
|
202
|
+
* decides for each whether it is safe and wanted: its type is read from its content, its
|
|
203
|
+
* name made safe, and the limits applied. Nothing is uploaded or read whole (except with
|
|
204
|
+
* `digest`): only each file's first 8 KiB.
|
|
205
|
+
*
|
|
206
|
+
* Call it from the event handler, before anything is awaited: a `DataTransfer` is emptied
|
|
207
|
+
* when its event ends. Folders are read through `webkitGetAsEntry` (every current browser).
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* onDrop={(event) => {
|
|
211
|
+
* event.preventDefault();
|
|
212
|
+
* void acceptFiles(event, { accept: '.pdf,image/*', maxFileBytes: 20e6 }).then(({ accepted, rejected }) => { ... });
|
|
213
|
+
* }}
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @throws {CopyFailure} `aborted` when `signal` aborts; `unsupported` for `digest` without Web Crypto;
|
|
217
|
+
* `invalid-payload` for a negative limit.
|
|
218
|
+
*/
|
|
219
|
+
export declare function acceptFiles(source: FileSource, options?: AcceptFilesOptions): Promise<AcceptFilesResult>;
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/files/detect.d.ts
|
|
222
|
+
/** How many leading bytes {@link detectFileType} reads: enough for every signature and a text sniff. */
|
|
223
|
+
export declare const FILE_SNIFF_BYTES = 8192;
|
|
224
|
+
/** Every type this module recognises, by MIME type. */
|
|
225
|
+
export declare const FILE_TYPES: {
|
|
226
|
+
readonly pdf: DetectedType;
|
|
227
|
+
readonly png: DetectedType;
|
|
228
|
+
readonly jpeg: DetectedType;
|
|
229
|
+
readonly gif: DetectedType;
|
|
230
|
+
readonly webp: DetectedType;
|
|
231
|
+
readonly avif: DetectedType;
|
|
232
|
+
readonly heic: DetectedType;
|
|
233
|
+
readonly bmp: DetectedType;
|
|
234
|
+
readonly ico: DetectedType;
|
|
235
|
+
readonly tiff: DetectedType;
|
|
236
|
+
readonly psd: DetectedType;
|
|
237
|
+
readonly svg: DetectedType;
|
|
238
|
+
readonly mp3: DetectedType;
|
|
239
|
+
readonly wav: DetectedType;
|
|
240
|
+
readonly flac: DetectedType;
|
|
241
|
+
readonly ogg: DetectedType;
|
|
242
|
+
readonly m4a: DetectedType;
|
|
243
|
+
readonly mp4: DetectedType;
|
|
244
|
+
readonly mov: DetectedType;
|
|
245
|
+
readonly threegp: DetectedType;
|
|
246
|
+
readonly webm: DetectedType;
|
|
247
|
+
readonly mkv: DetectedType;
|
|
248
|
+
readonly avi: DetectedType;
|
|
249
|
+
readonly zip: DetectedType;
|
|
250
|
+
readonly docx: DetectedType;
|
|
251
|
+
readonly xlsx: DetectedType;
|
|
252
|
+
readonly pptx: DetectedType;
|
|
253
|
+
readonly odt: DetectedType;
|
|
254
|
+
readonly ods: DetectedType;
|
|
255
|
+
readonly odp: DetectedType;
|
|
256
|
+
readonly epub: DetectedType;
|
|
257
|
+
readonly jar: DetectedType;
|
|
258
|
+
readonly apk: DetectedType;
|
|
259
|
+
readonly ole: DetectedType;
|
|
260
|
+
readonly rtf: DetectedType;
|
|
261
|
+
readonly gzip: DetectedType;
|
|
262
|
+
readonly bzip2: DetectedType;
|
|
263
|
+
readonly xz: DetectedType;
|
|
264
|
+
readonly zstd: DetectedType;
|
|
265
|
+
readonly sevenZip: DetectedType;
|
|
266
|
+
readonly rar: DetectedType;
|
|
267
|
+
readonly tar: DetectedType;
|
|
268
|
+
readonly sqlite: DetectedType;
|
|
269
|
+
readonly woff: DetectedType;
|
|
270
|
+
readonly woff2: DetectedType;
|
|
271
|
+
readonly otf: DetectedType;
|
|
272
|
+
readonly ttf: DetectedType;
|
|
273
|
+
readonly exe: DetectedType;
|
|
274
|
+
readonly elf: DetectedType;
|
|
275
|
+
readonly macho: DetectedType;
|
|
276
|
+
readonly wasm: DetectedType;
|
|
277
|
+
readonly shortcut: DetectedType;
|
|
278
|
+
readonly script: DetectedType;
|
|
279
|
+
readonly html: DetectedType;
|
|
280
|
+
readonly xml: DetectedType;
|
|
281
|
+
readonly json: DetectedType;
|
|
282
|
+
readonly text: DetectedType;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* The type of a file's content, from its leading bytes: never from its name or claimed type.
|
|
286
|
+
* Reads at most {@link FILE_SNIFF_BYTES}. `null` when the content is not a recognised type.
|
|
287
|
+
*/
|
|
288
|
+
export declare function detectFileType(bytes: Uint8Array, options?: {
|
|
289
|
+
readonly complete?: boolean;
|
|
290
|
+
}): DetectedType | null;
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/files/inspect.d.ts
|
|
293
|
+
interface InspectFileOptions {
|
|
294
|
+
/** The file's name. Default: `file.name`, for a `File`. */
|
|
295
|
+
readonly name?: string;
|
|
296
|
+
/** The type it claims. Default: `file.type`. Kept for reference only: never trusted. */
|
|
297
|
+
readonly declaredType?: string;
|
|
298
|
+
/** How {@link FileInspection.safeName} is made. */
|
|
299
|
+
readonly names?: SafeFileNameOptions;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* What a file really is, and why it may be unsafe to accept: its type from its content (never
|
|
303
|
+
* its name or claimed type), whether that contradicts its extension, and its risks.
|
|
304
|
+
* Reads only the first {@link FILE_SNIFF_BYTES} bytes, so it is fast for any size. Server-safe.
|
|
305
|
+
*
|
|
306
|
+
* @throws {CopyFailure} `invalid-payload` when `file` is not a Blob.
|
|
307
|
+
*/
|
|
308
|
+
export declare function inspectFile(file: Blob, options?: InspectFileOptions): Promise<FileInspection>;
|
|
309
|
+
//#endregion
|
|
310
|
+
export type { AcceptFilesOptions, AcceptFilesResult, AcceptedFile, DetectedType, FileFamily, FileInspection, FileRejectReason, FileRisk, FileSource, InspectFileOptions, RejectedFile, SafeFileNameOptions };
|
|
311
|
+
//# sourceMappingURL=files.d.cts.map
|