UNPKG

5.48 kBTypeScriptView Raw
1export interface IMounterOptions {
2 /**
3 * The path for hdiutil.
4 *
5 * @default 'hdiutil'
6 */
7 hdiutil?: string | null;
8}
9export interface IMounterAttachOptions {
10 /**
11 * Force the devices to be read-only.
12 */
13 readonly?: boolean;
14 /**
15 * Hide any mounted volumes from applications like Finder.
16 */
17 nobrowse?: boolean;
18}
19export interface IMounterEjectOptions {
20 /**
21 * Forcibly detach.
22 */
23 force?: boolean;
24}
25export interface IMounterDevice {
26 /**
27 * The dev-entry hdiutil info.
28 */
29 devEntry: string;
30 /**
31 * The potentially-mountable hdiutil info.
32 */
33 potentiallyMountable: boolean;
34 /**
35 * The content-hint hdiutil info.
36 */
37 contentHint?: string;
38 /**
39 * The unmapped-content-hint hdiutil info.
40 */
41 unmappedContentHint?: string;
42 /**
43 * The volume-kind hdiutil info, if present.
44 */
45 volumeKind?: string;
46 /**
47 * The mount-point hdiutil info, if present.
48 */
49 mountPoint?: string;
50}
51export interface IMounterAttachInfo {
52 /**
53 * Device list.
54 */
55 devices: IMounterDevice[];
56 /**
57 * Eject disk.
58 */
59 eject(options?: Readonly<IMounterEjectOptions> | null): Promise<void>;
60 /**
61 * Eject disk.
62 */
63 ejectSync(options?: Readonly<IMounterEjectOptions> | null): void;
64}
65/**
66 * Mounter object.
67 */
68export declare class Mounter {
69 /**
70 * The path to hdiutil.
71 */
72 hdiutil: string;
73 /**
74 * Mounter constructor.
75 *
76 * @param options Options object.
77 */
78 constructor(options?: Readonly<IMounterOptions> | null);
79 /**
80 * Attach a disk image.
81 *
82 * @param file Path to disk image.
83 * @param options Options object.
84 * @param ejectOnExit Eject on exit options, or null.
85 * @returns Info object.
86 */
87 attach(file: string, options?: Readonly<IMounterAttachOptions> | null, ejectOnExit?: Readonly<IMounterEjectOptions> | null): Promise<IMounterAttachInfo>;
88 /**
89 * Attach a disk image.
90 *
91 * @param file Path to disk image.
92 * @param options Options object.
93 * @param ejectOnExit Eject on exit options, or null.
94 * @returns Info object.
95 */
96 attachSync(file: string, options?: Readonly<IMounterAttachOptions> | null, ejectOnExit?: Readonly<IMounterEjectOptions> | null): IMounterAttachInfo;
97 /**
98 * Eject a disk image.
99 *
100 * @param file Path to device file or volume mount point.
101 * @param options Options object.
102 */
103 eject(file: string, options?: Readonly<IMounterEjectOptions> | null): Promise<void>;
104 /**
105 * Eject a disk image.
106 *
107 * @param file Path to device file or volume mount point.
108 * @param options Options object.
109 */
110 ejectSync(file: string, options?: Readonly<IMounterEjectOptions> | null): void;
111 /**
112 * Create args for attach.
113 *
114 * @param file Path to disk image.
115 * @param options Options object.
116 * @returns Argument list.
117 */
118 protected _argsAttach(file: string, options?: Readonly<IMounterAttachOptions> | null): string[];
119 /**
120 * Create args for eject.
121 *
122 * @param file Path to device file or volume mount point.
123 * @param options Options object.
124 * @returns Argument list.
125 */
126 protected _argsEject(file: string, options?: Readonly<IMounterEjectOptions> | null): string[];
127 /**
128 * Run hdiutil attach command, returning the devices list on success.
129 *
130 * @param args CLI args.
131 * @returns Devices list.
132 */
133 protected _runAttach(args: Readonly<string[]>): Promise<IMounterDevice[]>;
134 /**
135 * Run hdiutil attach command, returning the devices list on success.
136 *
137 * @param args CLI args.
138 * @returns Devices list.
139 */
140 protected _runAttachSync(args: Readonly<string[]>): IMounterDevice[];
141 /**
142 * Run hdiutil eject command.
143 *
144 * @param args CLI args.
145 */
146 protected _runEject(args: Readonly<string[]>): Promise<void>;
147 /**
148 * Run hdiutil eject command.
149 *
150 * @param args CLI args.
151 */
152 protected _runEjectSync(args: Readonly<string[]>): void;
153 /**
154 * Create file argument from file path.
155 *
156 * @param file File path.
157 * @returns A path for use as argument.
158 */
159 protected _fileArg(file: string): string;
160 /**
161 * Parse devices plist into devices list.
162 *
163 * @param xml XML plist.
164 * @returns Devices list.
165 */
166 protected _parseDevices(xml: string): IMounterDevice[];
167 /**
168 * Find the root device, null on empty list.
169 *
170 * @param devices Device list.
171 * @returns Root device or null if an empty list.
172 */
173 protected _findRootDevice(devices: Readonly<Readonly<IMounterDevice>[]>): IMounterDevice | null;
174 /**
175 * Create ejects callback from a list of devices.
176 *
177 * @param devices Device list.
178 * @param ejectOnExit Eject on exit options, or null.
179 * @returns Callback function.
180 */
181 protected _createEjects(devices: Readonly<Readonly<IMounterDevice>[]>, ejectOnExit?: null): {
182 /**
183 * The eject callback function.
184 *
185 * @param options Eject options.
186 */
187 eject: (options?: IMounterEjectOptions | null) => Promise<void>;
188 /**
189 * The eject callback function.
190 *
191 * @param options Eject options.
192 */
193 ejectSync: (options?: IMounterEjectOptions | null) => void;
194 };
195}