{"repo":"sindresorhus/file-type","free":true,"listed":false,"github":"https://github.com/sindresorhus/file-type","clone":"git clone https://github.com/sindresorhus/file-type.git","description":"Detect the file type of a file, stream, or data","language":"JavaScript","stars":4320,"topics":["nodejs","javascript","uint8array","buffer","magic-numbers","file","magic","file-types","detect"],"license":"MIT","category":"dev-tools","readme_excerpt":"Detect the file type of a file, stream, or data The file type is detected by checking the magic number#Magic numbers in files) of the buffer. This package is for detecting binary-based file formats, not text-based formats like .txt , .csv , .svg , etc. We accept contributions for commonly used modern file formats, not historical or obscure ones. Open an issue first for discussion. Install This package is an ESM package. Your project needs to be ESM too. Read more. For TypeScript + CommonJS, see load-esm . If you use it with Webpack, you need the latest Webpack version and ensure you configure it correctly for ESM. [!IMPORTANT] File type detection is based on binary signatures (magic numbers) and is a best-effort hint. It does not guarantee the file is actually of that type or that the file is valid/not malformed. Robustness against malformed input is best-effort. When processing untrusted files on a server, enforce a reasonable file size limit and use a worker thread with a timeout (e.g., make-asynchronous ). These are not considered security issues in this package. Usage Node.js Determine file type from a file: Determine file type from a Uint8Array/ArrayBuffer, which may be a portion of the beginning of a file: Determine file type from a stream: API fileTypeFromBuffer(buffer, options) Detect the file type of a Uint8Array or ArrayBuffer . The file type is detected by checking the magic number#Magic numbers in files) of the buffer. If file access is available, it is recommende","default_branch":null,"files":null,"tree":[],"storefront":"/r/sindresorhus","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/sindresorhus/file-type/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}