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