-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypes.d.ts
More file actions
87 lines (77 loc) · 2.52 KB
/
types.d.ts
File metadata and controls
87 lines (77 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
declare module 'mimetics' {
/**
* File type definition object.
*/
interface FileType {
tag: string
type: string
ext: string | string[]
mime: string
score?: number
pattern?: RegExp
zipped?: boolean | string[]
magic?: number[] | number[][]
}
/**
* CONSTANTS used in Mimetics library.
*/
export const CONSTANTS: {
BUFFER_CHECK_SIZE: number
MAGIC_NUMBER_SCORE: number
ZIP_HEADER_SCORE: number
}
/**
* Error messages used in the Mimetics library.
*/
export const ERRORS: {
INVALID_BUFFER: string
}
/**
* Mimetics class for detecting file types based on magic bytes, patterns, and other properties.
*/
class Mimetics {
/**
* Synchronously parses a buffer to identify the file type.
* @param buffer - The file buffer to parse.
* @param name - Optional file name, useful for detection.
* @returns A file type object or null if no match is found.
*/
parse(buffer: Uint8Array | ArrayBuffer, name?: string): FileType | null
/**
* Synchronously parses a buffer and returns all matching file types.
* @param buffer - The file buffer to parse.
* @param name - Optional file name, useful for detection.
* @returns Array of matching file types.
*/
parseSync(buffer: Uint8Array | ArrayBuffer, name?: string): FileType[]
/**
* Asynchronously parses a buffer to identify the file type, with support for ZIP analysis.
* @param buffer - The file buffer to parse.
* @param name - Optional file name, useful for detection.
* @returns A promise resolving to a file type object or null if no match is found.
*/
parseAsync(buffer: Uint8Array | ArrayBuffer, name?: string): Promise<FileType | null>
/**
* Determines file type from a file name extension.
* @param filePath - Path or name of the file.
* @returns File type object based on the extension or null if not found.
*/
fromName(filePath: string): FileType | null
/**
* Asynchronously determines file type from a File object in a browser environment.
* @param file - The file object to analyze.
* @returns A promise resolving to a file type object.
*/
fromFile(file: File): Promise<FileType | null>
/**
* Adds custom file definitions.
* @param definitions - Array of custom definitions to add.
*/
addDefinitions(definitions: FileType | FileType[]): void
}
/**
* The singleton instance of Mimetics.
*/
declare const mimetics: Mimetics
export default mimetics
}