## Classes
ObjectCollection of constants used in the Mimetics library.
Object.<string, string>Collection of error messages used in the library.
Object \| null
* [.parseSync(buffer, name)](#Mimetics+parseSync) ⇒ Array.<Object>
* [.parseAsync(buffer, name)](#Mimetics+parseAsync) ⇒ Promise.<(Object\|null)>
* [.magicMatch(magic, buffer)](#Mimetics+magicMatch) ⇒ boolean
* [.detectByMagicNumber(buffer)](#Mimetics+detectByMagicNumber) ⇒ Array.<Object>
* [.sortMatches(matches)](#Mimetics+sortMatches) ⇒ Array.<Object>
* [.analyzeZipContents(buffer, matches)](#Mimetics+analyzeZipContents) ⇒ Promise.<Array.<Object>>
* [.sniffContent(buffer)](#Mimetics+sniffContent) ⇒ Array.<Object>
* [.decodeBufferToString(buffer)](#Mimetics+decodeBufferToString) ⇒ string
* [.buildResponse(definition)](#Mimetics+buildResponse) ⇒ Object \| null
* [.defaultResponse()](#Mimetics+defaultResponse) ⇒ Object
* [.validateBuffer(buffer)](#Mimetics+validateBuffer)
* [.parseFileName(filePath)](#Mimetics+parseFileName) ⇒ Object
* [.fromName(filePath)](#Mimetics+fromName) ⇒ Object
* [.getBufferFromFile(file)](#Mimetics+getBufferFromFile) ⇒ Promise.<Uint8Array>
* [.fromFile(file)](#Mimetics+fromFile) ⇒ Promise.<Object>
### new Mimetics()
Singleton instance of Mimetics
**Returns**: [Mimetics](#Mimetics) - - Singleton instance of Mimetics class
### mimetics.parse(buffer, name) ⇒ Object \| null
Parses the buffer synchronously and returns the first matching file type.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Object \| null - - File type object or null if no match found.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer to parse. |
| name | string | Optional name of the file. |
### mimetics.parseSync(buffer, name) ⇒ Array.<Object>
Parses the buffer and returns all matching file types.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Array.<Object> - - List of matching file types.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer to parse. |
| name | string | Optional name of the file. |
### mimetics.parseAsync(buffer, name) ⇒ Promise.<(Object\|null)>
Parses the buffer asynchronously, analyzing ZIP contents if necessary.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Promise.<(Object\|null)> - - Promise resolving to the matching file type or null.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer to parse. |
| name | string | Optional name of the file. |
### mimetics.magicMatch(magic, buffer) ⇒ boolean
Matches a buffer against a specified magic byte sequence.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: boolean - - True if magic bytes match, otherwise false.
| Param | Type | Description |
| --- | --- | --- |
| magic | Array.<number> \| Array.<Array.<number>> | Expected magic byte(s). |
| buffer | Uint8Array \| ArrayBuffer | The buffer to match against. |
### mimetics.detectByMagicNumber(buffer) ⇒ Array.<Object>
Detects file type based on magic numbers within the buffer.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Array.<Object> - - Array of matching file definitions with scores.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer. |
### mimetics.sortMatches(matches) ⇒ Array.<Object>
Sorts matches by their score in descending order.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Array.<Object> - - Sorted matches.
| Param | Type | Description |
| --- | --- | --- |
| matches | Array.<Object> | List of matches to sort. |
### mimetics.analyzeZipContents(buffer, matches) ⇒ Promise.<Array.<Object>>
Analyzes ZIP contents for matching definitions based on required internal files.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Promise.<Array.<Object>> - - Array of verified matches with updated scores.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The ZIP file buffer. |
| matches | Array.<Object> | List of initial matches to verify. |
### mimetics.sniffContent(buffer) ⇒ Array.<Object>
Attempts to match file type based on content patterns.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Array.<Object> - - Array of file type definitions that match by content pattern.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer. |
### mimetics.decodeBufferToString(buffer) ⇒ string
Decodes a buffer into a string for pattern matching.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: string - - Decoded string content.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The file buffer. |
### mimetics.buildResponse(definition) ⇒ Object \| null
Constructs a response object based on a file type definition.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Object \| null - - Constructed response object, or null if no definition provided.
| Param | Type | Description |
| --- | --- | --- |
| definition | Object | The file type definition. |
### mimetics.defaultResponse() ⇒ Object
Returns a default response, typically for unknown or generic text file types.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Object - - Default response object.
### mimetics.validateBuffer(buffer)
Validates the provided buffer to ensure it’s a valid file buffer.
**Kind**: instance method of [Mimetics](#Mimetics)
**Throws**:
- Error - Throws if buffer is invalid.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Uint8Array \| ArrayBuffer | The buffer to validate. |
### mimetics.parseFileName(filePath) ⇒ Object
Parses a file name to extract metadata like extension and slug.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Object - - Object with parsed name, slug, path, and extension.
| Param | Type | Description |
| --- | --- | --- |
| filePath | string | Path or name of the file. |
### mimetics.fromName(filePath) ⇒ Object
Determines file type from file name extension.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Object - - File type definition or default response if not found.
| Param | Type | Description |
| --- | --- | --- |
| filePath | string | Path or name of the file. |
### mimetics.getBufferFromFile(file) ⇒ Promise.<Uint8Array>
Converts a file to a buffer asynchronously.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Promise.<Uint8Array> - - Promise resolving to the file buffer.
| Param | Type | Description |
| --- | --- | --- |
| file | File | The file object to read. |
### mimetics.fromFile(file) ⇒ Promise.<Object>
Determines file type from a file object by reading its buffer and name.
**Kind**: instance method of [Mimetics](#Mimetics)
**Returns**: Promise.<Object> - - Promise resolving to file type definition or null if not found.
| Param | Type | Description |
| --- | --- | --- |
| file | File | The file object to analyze. |
## CONSTANTS : Object
Collection of constants used in the Mimetics library.
**Kind**: global variable
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BUFFER_CHECK_SIZE | number | Number of bytes to check in a buffer for type detection. |
| MAGIC_NUMBER_SCORE | number | Score assigned to a file type when a magic number match is found. |
| ZIP_HEADER_SCORE | number | Additional score given to ZIP files that contain specific internal files. |
## ERRORS : Object.<string, string>
Collection of error messages used in the library.
**Kind**: global variable
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| INVALID_BUFFER | string | Error message for invalid buffer input. |