forked from p2r3/convert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatHandler.ts
More file actions
74 lines (71 loc) · 2.27 KB
/
FormatHandler.ts
File metadata and controls
74 lines (71 loc) · 2.27 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
export interface FileFormat {
/** Format description (long name) for displaying to the user. */
name: string;
/** Short, "formal" name for displaying to the user. */
format: string;
/** File extension. */
extension: string;
/** MIME type. */
mime: string;
/** Whether conversion **from** this format is supported. */
from: boolean;
/** Whether conversion **to** this format is supported. */
to: boolean;
/** Format identifier for the handler's internal reference. */
internal: string;
}
export interface FileData {
/** File name with extension. */
name: string;
/**
* File contents in bytes.
*
* **Please note:** _handlers_ are responsible for ensuring the lifetime
* and consistency of this buffer. If you're not sure that your handler
* won't modify it, wrap it in `new Uint8Array()`.
*/
readonly bytes: Uint8Array;
}
/**
* Establishes a common interface for converting between file formats.
* Often a "wrapper" for existing tools.
*/
export interface FormatHandler {
/** Name of the tool being wrapped (e.g. "FFmpeg"). */
name: string;
/** List of supported input/output {@link FileFormat}s. */
supportedFormats?: FileFormat[];
/**
* Whether the handler is ready for use. Should be set in {@link init}.
* If true, {@link doConvert} is expected to work.
*/
ready: boolean;
/**
* Initializes the handler if necessary.
* Should set {@link ready} to true.
*/
init: () => Promise<void>;
/**
* Performs the actual file conversion.
* @param inputFiles Array of {@link FileData} entries, one per input file.
* @param inputFormat Input {@link FileFormat}, the same for all inputs.
* @param outputFormat Output {@link FileFormat}, the same for all outputs.
* @param args Optional arguments as a string array.
* Can be used to perform recursion with different settings.
* @returns Array of {@link FileData} entries, one per generated output file.
*/
doConvert: (
inputFiles: FileData[],
inputFormat: FileFormat,
outputFormat: FileFormat,
args?: string[]
) => Promise<FileData[]>;
}
export class ConvertPathNode {
public handler: FormatHandler;
public format: FileFormat;
constructor (handler: FormatHandler, format: FileFormat) {
this.handler = handler;
this.format = format;
}
}