@signageos/front-applet 8.1.1 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.map +1 -1
- package/docs/sos/browser.md +66 -14
- package/docs/sos/command.md +52 -6
- package/docs/sos/debug.md +17 -2
- package/docs/sos/deviceInfo.md +27 -0
- package/docs/sos/display.md +34 -3
- package/docs/sos/fileSystem.md +1135 -59
- package/docs/sos/index.md +36 -12
- package/docs/sos/input.md +42 -1
- package/docs/sos/native/mdc.md +65 -19
- package/docs/sos/offline/cache.md +14 -8
- package/docs/sos/stream.md +1172 -37
- package/docs/sos/sync.md +2 -2
- package/docs/sos/video.md +515 -22
- package/docs/sos_management/security.md +4 -2
- package/docs/sos_management/wifi.md +9 -9
- package/es6/FrontApplet/Browser/Browser.d.ts +25 -9
- package/es6/FrontApplet/Browser/Browser.js +25 -9
- package/es6/FrontApplet/Browser/Browser.js.map +1 -1
- package/es6/FrontApplet/Browser/IOpenLinkOptions.d.ts +7 -0
- package/es6/FrontApplet/Browser/IOpenLinkOptions.js.map +1 -1
- package/es6/FrontApplet/Browser/events.d.ts +6 -0
- package/es6/FrontApplet/Browser/events.js.map +1 -1
- package/es6/FrontApplet/Command/Command.d.ts +15 -6
- package/es6/FrontApplet/Command/Command.js +15 -6
- package/es6/FrontApplet/Command/Command.js.map +1 -1
- package/es6/FrontApplet/Command/ICommand.d.ts +7 -0
- package/es6/FrontApplet/Command/ICommandEvent.d.ts +6 -0
- package/es6/FrontApplet/Debug/Debug.d.ts +11 -3
- package/es6/FrontApplet/Debug/Debug.js +11 -3
- package/es6/FrontApplet/Debug/Debug.js.map +1 -1
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.d.ts +15 -0
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.js +16 -2
- package/es6/FrontApplet/DeviceInfo/DeviceInfo.js.map +1 -1
- package/es6/FrontApplet/Display/Display.d.ts +22 -14
- package/es6/FrontApplet/Display/Display.js +22 -14
- package/es6/FrontApplet/Display/Display.js.map +1 -1
- package/es6/FrontApplet/Display/IDisplay.d.ts +4 -0
- package/es6/FrontApplet/FileSystem/FileSystem.d.ts +429 -41
- package/es6/FrontApplet/FileSystem/FileSystem.js +427 -39
- package/es6/FrontApplet/FileSystem/FileSystem.js.map +1 -1
- package/es6/FrontApplet/FileSystem/HashAlgorithm.d.ts +4 -1
- package/es6/FrontApplet/FileSystem/types.d.ts +46 -0
- package/es6/FrontApplet/FileSystem/types.js.map +1 -1
- package/es6/FrontApplet/FrontApplet.d.ts +31 -7
- package/es6/FrontApplet/FrontApplet.js +32 -8
- package/es6/FrontApplet/FrontApplet.js.map +1 -1
- package/es6/FrontApplet/Input/IKeyUpEvent.d.ts +9 -0
- package/es6/FrontApplet/Input/IKeyUpEvent.js +6 -0
- package/es6/FrontApplet/Input/IKeyUpEvent.js.map +1 -1
- package/es6/FrontApplet/Input/Input.d.ts +17 -1
- package/es6/FrontApplet/Input/Input.js +17 -1
- package/es6/FrontApplet/Input/Input.js.map +1 -1
- package/es6/FrontApplet/NativeCommands/MDC/Mdc.d.ts +32 -11
- package/es6/FrontApplet/NativeCommands/MDC/Mdc.js +14 -11
- package/es6/FrontApplet/NativeCommands/MDC/Mdc.js.map +1 -1
- package/es6/FrontApplet/Stream/IStreamTrackInfo.d.ts +34 -0
- package/es6/FrontApplet/Stream/Stream.d.ts +245 -20
- package/es6/FrontApplet/Stream/Stream.js +245 -20
- package/es6/FrontApplet/Stream/Stream.js.map +1 -1
- package/es6/FrontApplet/Stream/StreamProtocol.d.ts +4 -0
- package/es6/FrontApplet/Stream/StreamProtocol.js +4 -0
- package/es6/FrontApplet/Stream/StreamProtocol.js.map +1 -1
- package/es6/FrontApplet/Stream/streamEventProperties.d.ts +11 -1
- package/es6/FrontApplet/Stream/streamEvents.d.ts +26 -0
- package/es6/FrontApplet/Video/IOptions.d.ts +41 -0
- package/es6/FrontApplet/Video/IVideoEvent.d.ts +8 -0
- package/es6/FrontApplet/Video/IVideoEvent.js.map +1 -1
- package/es6/FrontApplet/Video/IVideoProperties.d.ts +3 -0
- package/es6/FrontApplet/Video/Video.d.ts +256 -19
- package/es6/FrontApplet/Video/Video.js +258 -22
- package/es6/FrontApplet/Video/Video.js.map +1 -1
- package/package.json +1 -1
package/docs/sos/fileSystem.md
CHANGED
|
@@ -4,69 +4,173 @@ sidebar_position: 0
|
|
|
4
4
|
|
|
5
5
|
# fileSystem
|
|
6
6
|
|
|
7
|
-
<Admonition type="info" icon="" title="">
|
|
8
|
-
Learn more about using this API [here](https://developers.signageos.io/docs/applets/api-guides/offline-content#storing-files-permanently)
|
|
9
|
-
</Admonition>
|
|
10
|
-
|
|
11
7
|
The `sos.fileSystem` API groups together methods for low-level access to the file system. The File System API supports both internal and
|
|
12
8
|
external storage.
|
|
13
9
|
|
|
14
|
-
:::warning
|
|
15
|
-
|
|
10
|
+
:::warning Differences between File System API and Offline Cache API
|
|
16
11
|
File System directory structure is **PERSISTENT** and is **NOT** automatically deleted through `Applet Reload` power action!
|
|
17
12
|
Applet Reload only deletes `/data` directory which is reserved for simplified [Offline Cache API](./offline). Use
|
|
18
13
|
`deleteFile()` to clear the device storage file system.
|
|
14
|
+
:::
|
|
19
15
|
|
|
16
|
+
:::info GitHub Example
|
|
17
|
+
- [Example usage of File System API in Applet](https://github.com/signageos/applet-examples/tree/master/examples/content-js-api/file-system)
|
|
20
18
|
:::
|
|
21
19
|
|
|
20
|
+
|
|
21
|
+
## Storing files permanently
|
|
22
|
+
To allow more low-level file operations, the applet SDK exposes the File System API. Files created using this API are permanent and are only removed on a factory reset or file system wipeout.
|
|
23
|
+
The file system is also shared between all applets, which means you cannot rely on any file system structure on startup because a different applet on the device could have saved files you didn't expect.
|
|
24
|
+
To mitigate this issue, create a directory for your applet and save all files inside it.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import sos from '@signageos/front-applet';
|
|
28
|
+
|
|
29
|
+
sos.onReady(async () => {
|
|
30
|
+
const storageUnits = await sos.fileSystem.listStorageUnits();
|
|
31
|
+
const rootPath = {
|
|
32
|
+
filePath: '', // Empty string is used as an absolute path instead of "/"
|
|
33
|
+
storageUnit: storageUnits.find((s) => !s.removable), // Find internal storage
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// This will return files previous applets saved to the device
|
|
37
|
+
const files = await sos.fileSystem.listFiles(rootPath);
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
22
41
|
## Methods
|
|
23
42
|
|
|
24
43
|
### appendFile()
|
|
25
44
|
|
|
26
|
-
The `
|
|
27
|
-
does
|
|
45
|
+
The `appendFile()` method appends string content to the file specified by `filePath`.
|
|
46
|
+
If the file does exist, it is created.
|
|
47
|
+
|
|
48
|
+
:::note
|
|
49
|
+
Only string can be appended to the file. If you want to append binary data, you have to convert it to a string first.
|
|
50
|
+
:::
|
|
28
51
|
|
|
29
52
|
```ts expandable
|
|
30
53
|
appendFile(filePath: IFilePath, contents: string): Promise<void>;
|
|
31
54
|
// show-more
|
|
55
|
+
/**
|
|
56
|
+
* Base File System interface for methods.
|
|
57
|
+
*/
|
|
32
58
|
interface IFilePath {
|
|
59
|
+
/**
|
|
60
|
+
* Storage unit which is selected for performing file operations.
|
|
61
|
+
*/
|
|
33
62
|
storageUnit: IStorageUnit;
|
|
63
|
+
/**
|
|
64
|
+
* File path within the storage unit.
|
|
65
|
+
*/
|
|
34
66
|
filePath: string;
|
|
35
67
|
}
|
|
36
68
|
|
|
69
|
+
/**
|
|
70
|
+
* File System Storage Unit returned by the File System API.
|
|
71
|
+
*/
|
|
37
72
|
interface IStorageUnit {
|
|
73
|
+
/**
|
|
74
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
75
|
+
*/
|
|
38
76
|
type: string;
|
|
77
|
+
/**
|
|
78
|
+
* The total capacity of the storage unit in bytes.
|
|
79
|
+
*/
|
|
39
80
|
capacity: number;
|
|
81
|
+
/**
|
|
82
|
+
* The amount of free space available in the storage unit in bytes.
|
|
83
|
+
*/
|
|
40
84
|
freeSpace: number;
|
|
85
|
+
/**
|
|
86
|
+
* The amount of usable space in the storage unit in bytes.
|
|
87
|
+
*/
|
|
41
88
|
usableSpace: number;
|
|
89
|
+
/**
|
|
90
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
91
|
+
*/
|
|
42
92
|
removable: boolean;
|
|
43
93
|
}
|
|
44
94
|
|
|
45
95
|
```
|
|
46
96
|
|
|
97
|
+
#### Params
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
|------------|-------------|-----------------------------------------|
|
|
101
|
+
| `filePath` | `IFilePath` | The path to the file to be appended. |
|
|
102
|
+
| `contents` | `string` | The content to be appended to the file. |
|
|
103
|
+
|
|
104
|
+
#### Return value
|
|
105
|
+
|
|
106
|
+
A promise that resolves when the content is appended successfully.
|
|
107
|
+
|
|
47
108
|
#### Possible errors
|
|
48
109
|
|
|
49
|
-
|
|
110
|
+
|
|
111
|
+
- Error If the parent directory does not exist.
|
|
112
|
+
- Error If the `filePath` is a directory.
|
|
113
|
+
- Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
114
|
+
- Error If any error occurs during the append operation on the device.
|
|
115
|
+
|
|
116
|
+
#### Example
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const filePath = {
|
|
120
|
+
storageUnit: internalStorageUnit,
|
|
121
|
+
filePath: 'path/to/file.txt',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const contents = 'This is the content to append to the file.';
|
|
125
|
+
await sos.fileSystem.appendFile(filePath, contents);
|
|
126
|
+
```
|
|
50
127
|
|
|
51
128
|
<Separator />
|
|
52
129
|
|
|
53
130
|
### copyFile()
|
|
54
131
|
|
|
55
|
-
The `copyFile()` method creates a copy of file
|
|
132
|
+
The `copyFile()` method creates a copy of file from `sourceFilePath` to `destinationFilePath`.
|
|
56
133
|
|
|
57
134
|
```ts expandable
|
|
58
135
|
copyFile(sourceFilePath: IFilePath, destinationFilePath: IFilePath, options?: ICopyFileOptions): Promise<void>;
|
|
59
136
|
// show-more
|
|
137
|
+
/**
|
|
138
|
+
* Base File System interface for methods.
|
|
139
|
+
*/
|
|
60
140
|
interface IFilePath {
|
|
141
|
+
/**
|
|
142
|
+
* Storage unit which is selected for performing file operations.
|
|
143
|
+
*/
|
|
61
144
|
storageUnit: IStorageUnit;
|
|
145
|
+
/**
|
|
146
|
+
* File path within the storage unit.
|
|
147
|
+
*/
|
|
62
148
|
filePath: string;
|
|
63
149
|
}
|
|
64
150
|
|
|
151
|
+
/**
|
|
152
|
+
* File System Storage Unit returned by the File System API.
|
|
153
|
+
*/
|
|
65
154
|
interface IStorageUnit {
|
|
155
|
+
/**
|
|
156
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
157
|
+
*/
|
|
66
158
|
type: string;
|
|
159
|
+
/**
|
|
160
|
+
* The total capacity of the storage unit in bytes.
|
|
161
|
+
*/
|
|
67
162
|
capacity: number;
|
|
163
|
+
/**
|
|
164
|
+
* The amount of free space available in the storage unit in bytes.
|
|
165
|
+
*/
|
|
68
166
|
freeSpace: number;
|
|
167
|
+
/**
|
|
168
|
+
* The amount of usable space in the storage unit in bytes.
|
|
169
|
+
*/
|
|
69
170
|
usableSpace: number;
|
|
171
|
+
/**
|
|
172
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
173
|
+
*/
|
|
70
174
|
removable: boolean;
|
|
71
175
|
}
|
|
72
176
|
|
|
@@ -78,116 +182,335 @@ interface ICopyFileOptions {
|
|
|
78
182
|
|
|
79
183
|
#### Params
|
|
80
184
|
|
|
81
|
-
| Name | Type
|
|
82
|
-
|
|
83
|
-
| `
|
|
185
|
+
| Name | Type | Description |
|
|
186
|
+
|----------------------------------|--------------------|----------------------------------------------------------------------------------------|
|
|
187
|
+
| `sourceFilePath` | `IFilePath` | The path to the file to be copied. |
|
|
188
|
+
| `destinationFilePath` | `IFilePath` | The path where the file will be copied to. |
|
|
189
|
+
| `options` *(optional)* | `ICopyFileOptions` | Options for copying the file. |
|
|
190
|
+
| `options.overwrite` *(optional)* | `boolean` | If set to `true`, the method will overwrite the destination file if it already exists. |
|
|
191
|
+
|
|
192
|
+
#### Return value
|
|
193
|
+
|
|
194
|
+
A promise that resolves when the file is copied successfully.
|
|
84
195
|
|
|
85
196
|
#### Possible errors
|
|
86
197
|
|
|
87
|
-
|
|
88
|
-
|
|
198
|
+
|
|
199
|
+
- Error If the source file does not exist.
|
|
200
|
+
- Error If parent of the destination file path does not exist.
|
|
201
|
+
- Error If `options` object is not valid.
|
|
202
|
+
- Error If any error occurs during the copy operation on the device.
|
|
203
|
+
|
|
204
|
+
#### Example
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
// Copy file from one directory to another and overwrite it if it already exists
|
|
208
|
+
const sourceFilePath = {
|
|
209
|
+
storageUnit: internalStorageUnit,
|
|
210
|
+
filePath: 'path/to/source/file.txt',
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const destinationFilePath = {
|
|
214
|
+
storageUnit: internalStorageUnit,
|
|
215
|
+
filePath: 'path/to/destination/file.txt',
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
await sos.fileSystem.copyFile(sourceFilePath, destinationFilePath, { overwrite: true });
|
|
219
|
+
```
|
|
89
220
|
|
|
90
221
|
<Separator />
|
|
91
222
|
|
|
92
223
|
### createArchive()
|
|
93
224
|
|
|
94
|
-
The `createArchive()` method creates an
|
|
225
|
+
The `createArchive()` method creates an archive file from selected files and directories.
|
|
95
226
|
|
|
96
227
|
:::warning
|
|
228
|
+
- Never start OR end the `filePath` with a slash - `/`.
|
|
229
|
+
- It is a good practice to check if file exists - `exists()` prior creating it
|
|
230
|
+
:::
|
|
97
231
|
|
|
98
|
-
|
|
99
|
-
|
|
232
|
+
:::info
|
|
233
|
+
- This function is available only on Tizen devices.
|
|
234
|
+
- All files are added to the archive based on absolute path from root directory.
|
|
100
235
|
:::
|
|
101
236
|
|
|
102
237
|
```ts expandable
|
|
103
238
|
createArchive(archiveFilePath: IFilePath, archiveEntries: IFilePath[]): Promise<void>;
|
|
104
239
|
// show-more
|
|
240
|
+
/**
|
|
241
|
+
* Base File System interface for methods.
|
|
242
|
+
*/
|
|
105
243
|
interface IFilePath {
|
|
244
|
+
/**
|
|
245
|
+
* Storage unit which is selected for performing file operations.
|
|
246
|
+
*/
|
|
106
247
|
storageUnit: IStorageUnit;
|
|
248
|
+
/**
|
|
249
|
+
* File path within the storage unit.
|
|
250
|
+
*/
|
|
107
251
|
filePath: string;
|
|
108
252
|
}
|
|
109
253
|
|
|
254
|
+
/**
|
|
255
|
+
* File System Storage Unit returned by the File System API.
|
|
256
|
+
*/
|
|
110
257
|
interface IStorageUnit {
|
|
258
|
+
/**
|
|
259
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
260
|
+
*/
|
|
111
261
|
type: string;
|
|
262
|
+
/**
|
|
263
|
+
* The total capacity of the storage unit in bytes.
|
|
264
|
+
*/
|
|
112
265
|
capacity: number;
|
|
266
|
+
/**
|
|
267
|
+
* The amount of free space available in the storage unit in bytes.
|
|
268
|
+
*/
|
|
113
269
|
freeSpace: number;
|
|
270
|
+
/**
|
|
271
|
+
* The amount of usable space in the storage unit in bytes.
|
|
272
|
+
*/
|
|
114
273
|
usableSpace: number;
|
|
274
|
+
/**
|
|
275
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
276
|
+
*/
|
|
115
277
|
removable: boolean;
|
|
116
278
|
}
|
|
117
279
|
|
|
118
280
|
```
|
|
119
281
|
|
|
282
|
+
#### Params
|
|
283
|
+
|
|
284
|
+
| Name | Type | Description |
|
|
285
|
+
|-------------------|---------------|-------------------------------------------------------|
|
|
286
|
+
| `archiveFilePath` | `IFilePath` | The path where the archive file will be created. |
|
|
287
|
+
| `archiveEntries` | `IFilePath[]` | An array of file paths to be included in the archive. |
|
|
288
|
+
|
|
289
|
+
#### Return value
|
|
290
|
+
|
|
291
|
+
A promise that resolves when the archive file is created successfully.
|
|
292
|
+
|
|
293
|
+
#### Possible errors
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
- Error If `archiveFilePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
297
|
+
- Error If `archiveEntries` is not a valid array of objects.
|
|
298
|
+
- Error If the parent directory of `archiveFilePath` does not exist.
|
|
299
|
+
- Error If any of the `archiveEntries` do not exist or are directories.
|
|
300
|
+
- Error If creating the archive file fails.
|
|
301
|
+
- Error If the platform does not support creating archive files.
|
|
302
|
+
|
|
303
|
+
#### Example
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
const archiveFilePath = {
|
|
307
|
+
storageUnit: internalStorageUnit,
|
|
308
|
+
filePath: 'path/to/archive.zip',
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const archiveEntries = [
|
|
312
|
+
{
|
|
313
|
+
storageUnit: internalStorageUnit,
|
|
314
|
+
filePath: 'path/to/file1.txt',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
storageUnit: internalStorageUnit,
|
|
318
|
+
filePath: 'path/to/file2.txt',
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
storageUnit: internalStorageUnit,
|
|
322
|
+
filePath: 'path/to/directory1',
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
await sos.fileSystem.createArchive(archiveFilePath, archiveEntries);
|
|
327
|
+
```
|
|
328
|
+
|
|
120
329
|
<Separator />
|
|
121
330
|
|
|
122
331
|
### createDirectory()
|
|
123
332
|
|
|
124
333
|
The `createDirectory()` method create a new directory at specified path.
|
|
125
334
|
|
|
335
|
+
:::warning
|
|
336
|
+
- Never start OR end the filePath with a slash - `/`.
|
|
337
|
+
- It is a good practice to check if directory exists - `isDirectory()` prior creating it.
|
|
338
|
+
:::
|
|
339
|
+
|
|
126
340
|
```ts expandable
|
|
127
341
|
createDirectory(directoryPath: IFilePath): Promise<void>;
|
|
128
342
|
// show-more
|
|
343
|
+
/**
|
|
344
|
+
* Base File System interface for methods.
|
|
345
|
+
*/
|
|
129
346
|
interface IFilePath {
|
|
347
|
+
/**
|
|
348
|
+
* Storage unit which is selected for performing file operations.
|
|
349
|
+
*/
|
|
130
350
|
storageUnit: IStorageUnit;
|
|
351
|
+
/**
|
|
352
|
+
* File path within the storage unit.
|
|
353
|
+
*/
|
|
131
354
|
filePath: string;
|
|
132
355
|
}
|
|
133
356
|
|
|
357
|
+
/**
|
|
358
|
+
* File System Storage Unit returned by the File System API.
|
|
359
|
+
*/
|
|
134
360
|
interface IStorageUnit {
|
|
361
|
+
/**
|
|
362
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
363
|
+
*/
|
|
135
364
|
type: string;
|
|
365
|
+
/**
|
|
366
|
+
* The total capacity of the storage unit in bytes.
|
|
367
|
+
*/
|
|
136
368
|
capacity: number;
|
|
369
|
+
/**
|
|
370
|
+
* The amount of free space available in the storage unit in bytes.
|
|
371
|
+
*/
|
|
137
372
|
freeSpace: number;
|
|
373
|
+
/**
|
|
374
|
+
* The amount of usable space in the storage unit in bytes.
|
|
375
|
+
*/
|
|
138
376
|
usableSpace: number;
|
|
377
|
+
/**
|
|
378
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
379
|
+
*/
|
|
139
380
|
removable: boolean;
|
|
140
381
|
}
|
|
141
382
|
|
|
142
383
|
```
|
|
143
384
|
|
|
385
|
+
#### Params
|
|
386
|
+
|
|
387
|
+
| Name | Type | Description |
|
|
388
|
+
|-----------------|-------------|---------------------------------------------------|
|
|
389
|
+
| `directoryPath` | `IFilePath` | The path where the new directory will be created. |
|
|
390
|
+
|
|
391
|
+
#### Return value
|
|
392
|
+
|
|
393
|
+
A promise that resolves when the directory is created successfully.
|
|
394
|
+
|
|
144
395
|
#### Possible errors
|
|
145
396
|
|
|
146
|
-
|
|
397
|
+
|
|
398
|
+
- Error If `directoryPath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
399
|
+
- Error If the directory already exists.
|
|
400
|
+
- Error If parent directory does not exist.
|
|
401
|
+
|
|
402
|
+
#### Example
|
|
403
|
+
|
|
404
|
+
```ts
|
|
405
|
+
const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
|
|
406
|
+
const directoryPath = {
|
|
407
|
+
storageUnit: internalStorageUnit,
|
|
408
|
+
filePath: 'path/to/new/directory',
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
await sos.fileSystem.createDirectory(directoryPath);
|
|
412
|
+
```
|
|
147
413
|
|
|
148
414
|
<Separator />
|
|
149
415
|
|
|
150
416
|
### deleteFile()
|
|
151
417
|
|
|
152
|
-
The `deleteFile()` method deletes the file specified by `filePath`.
|
|
418
|
+
The `deleteFile()` method deletes the file specified by `filePath`.
|
|
153
419
|
|
|
154
420
|
```ts expandable
|
|
155
421
|
deleteFile(filePath: IFilePath, recursive: boolean): Promise<void>;
|
|
156
422
|
// show-more
|
|
423
|
+
/**
|
|
424
|
+
* Base File System interface for methods.
|
|
425
|
+
*/
|
|
157
426
|
interface IFilePath {
|
|
427
|
+
/**
|
|
428
|
+
* Storage unit which is selected for performing file operations.
|
|
429
|
+
*/
|
|
158
430
|
storageUnit: IStorageUnit;
|
|
431
|
+
/**
|
|
432
|
+
* File path within the storage unit.
|
|
433
|
+
*/
|
|
159
434
|
filePath: string;
|
|
160
435
|
}
|
|
161
436
|
|
|
437
|
+
/**
|
|
438
|
+
* File System Storage Unit returned by the File System API.
|
|
439
|
+
*/
|
|
162
440
|
interface IStorageUnit {
|
|
441
|
+
/**
|
|
442
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
443
|
+
*/
|
|
163
444
|
type: string;
|
|
445
|
+
/**
|
|
446
|
+
* The total capacity of the storage unit in bytes.
|
|
447
|
+
*/
|
|
164
448
|
capacity: number;
|
|
449
|
+
/**
|
|
450
|
+
* The amount of free space available in the storage unit in bytes.
|
|
451
|
+
*/
|
|
165
452
|
freeSpace: number;
|
|
453
|
+
/**
|
|
454
|
+
* The amount of usable space in the storage unit in bytes.
|
|
455
|
+
*/
|
|
166
456
|
usableSpace: number;
|
|
457
|
+
/**
|
|
458
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
459
|
+
*/
|
|
167
460
|
removable: boolean;
|
|
168
461
|
}
|
|
169
462
|
|
|
170
463
|
```
|
|
171
464
|
|
|
465
|
+
#### Params
|
|
466
|
+
|
|
467
|
+
| Name | Type | Description |
|
|
468
|
+
|-------------|-------------|------------------------------------------------------------------------------------------|
|
|
469
|
+
| `filePath` | `IFilePath` | The path to the file or directory to be deleted. |
|
|
470
|
+
| `recursive` | `boolean` | If set to `true`, the method will delete the directory and all its contents recursively. |
|
|
471
|
+
|
|
472
|
+
#### Return value
|
|
473
|
+
|
|
474
|
+
A promise that resolves when the file is deleted successfully.
|
|
475
|
+
|
|
172
476
|
#### Possible errors
|
|
173
477
|
|
|
174
|
-
|
|
478
|
+
|
|
479
|
+
- Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
480
|
+
- Error If the file does not exist or if `recursive` is set to false and the file path is a directory.
|
|
481
|
+
- Error If deleting path does not exist.
|
|
482
|
+
- Error When is deleting directory and is not empty (not recursive).
|
|
483
|
+
|
|
484
|
+
#### Example
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
// Delete directory and all files inside
|
|
488
|
+
//// First check, if there is such a directory
|
|
489
|
+
if (await sos.fileSystem.exists({ storageUnit: internalStorageUnit, filePath: 'test-dir' })) {
|
|
490
|
+
// Delete the directory and all it's content recursively
|
|
491
|
+
await sos.fileSystem.deleteFile({ storageUnit: internalStorageUnit, filePath: 'test-dir' }, true);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Delete file
|
|
495
|
+
//// First check, if there is such a file
|
|
496
|
+
if (await sos.fileSystem.exists({ storageUnit: internalStorageUnit, filePath: 'test-dir/downloaded-file.png' })) {
|
|
497
|
+
// Delete the file
|
|
498
|
+
await sos.fileSystem.deleteFile({ storageUnit: internalStorageUnit, filePath: 'test-dir/downloaded-file.png' }, false);
|
|
499
|
+
}
|
|
500
|
+
```
|
|
175
501
|
|
|
176
502
|
<Separator />
|
|
177
503
|
|
|
178
504
|
### downloadFile()
|
|
179
505
|
|
|
180
|
-
The `downloadFile()` method download a file from `sourceUri` and saves it to the specified path. If the file already exists
|
|
181
|
-
overwritten. Optionally, headers for the download request may be specified.
|
|
182
|
-
of the downloaded file.
|
|
506
|
+
The `downloadFile()` method download a file from `sourceUri` and saves it to the specified path. If the file already exists, the file will be
|
|
507
|
+
overwritten. Optionally, headers for the download request may be specified.
|
|
183
508
|
|
|
184
|
-
:::
|
|
185
|
-
|
|
186
|
-
- Windows platform can download only files smaller then 4GB.
|
|
509
|
+
:::danger
|
|
510
|
+
For every download request, our Core Apps makes HEAD request for `content-length` header on that downloaded file. It's due to determining if device has enough space to download the file.
|
|
187
511
|
:::
|
|
188
512
|
|
|
189
513
|
#### Encoding
|
|
190
|
-
|
|
191
514
|
All downloads respect a standard of `Encoding` with optional compression of files. See [Mozilla standard Accept Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) and [Content Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding).
|
|
192
515
|
|
|
193
516
|
Download file method is always sending optional following headers:
|
|
@@ -220,16 +543,43 @@ The standard is supported on all following platforms:
|
|
|
220
543
|
```ts expandable
|
|
221
544
|
downloadFile(filePath: IFilePath, sourceUri: string, headers?: IHeaders): Promise<void>;
|
|
222
545
|
// show-more
|
|
546
|
+
/**
|
|
547
|
+
* Base File System interface for methods.
|
|
548
|
+
*/
|
|
223
549
|
interface IFilePath {
|
|
550
|
+
/**
|
|
551
|
+
* Storage unit which is selected for performing file operations.
|
|
552
|
+
*/
|
|
224
553
|
storageUnit: IStorageUnit;
|
|
554
|
+
/**
|
|
555
|
+
* File path within the storage unit.
|
|
556
|
+
*/
|
|
225
557
|
filePath: string;
|
|
226
558
|
}
|
|
227
559
|
|
|
560
|
+
/**
|
|
561
|
+
* File System Storage Unit returned by the File System API.
|
|
562
|
+
*/
|
|
228
563
|
interface IStorageUnit {
|
|
564
|
+
/**
|
|
565
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
566
|
+
*/
|
|
229
567
|
type: string;
|
|
568
|
+
/**
|
|
569
|
+
* The total capacity of the storage unit in bytes.
|
|
570
|
+
*/
|
|
230
571
|
capacity: number;
|
|
572
|
+
/**
|
|
573
|
+
* The amount of free space available in the storage unit in bytes.
|
|
574
|
+
*/
|
|
231
575
|
freeSpace: number;
|
|
576
|
+
/**
|
|
577
|
+
* The amount of usable space in the storage unit in bytes.
|
|
578
|
+
*/
|
|
232
579
|
usableSpace: number;
|
|
580
|
+
/**
|
|
581
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
582
|
+
*/
|
|
233
583
|
removable: boolean;
|
|
234
584
|
}
|
|
235
585
|
|
|
@@ -239,9 +589,40 @@ interface IHeaders {
|
|
|
239
589
|
|
|
240
590
|
```
|
|
241
591
|
|
|
592
|
+
#### Params
|
|
593
|
+
|
|
594
|
+
| Name | Type | Description |
|
|
595
|
+
|------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------|
|
|
596
|
+
| `filePath` | `IFilePath` | The path where the downloaded file will be saved. |
|
|
597
|
+
| `sourceUri` | `string` | The URI of the file to be downloaded. |
|
|
598
|
+
| `headers` *(optional)* | `IHeaders` | Key, value pairs of HTTP headers to send along with the request. Used when the target file is protected by a password or if any |
|
|
599
|
+
|
|
600
|
+
#### Return value
|
|
601
|
+
|
|
602
|
+
A promise that resolves when the file is downloaded successfully.
|
|
603
|
+
|
|
242
604
|
#### Possible errors
|
|
243
605
|
|
|
244
|
-
|
|
606
|
+
|
|
607
|
+
- Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
608
|
+
- Error If `sourceUri` is not a valid URI.
|
|
609
|
+
- Error If `headers` is not a valid object.
|
|
610
|
+
- Error If the parent directory of `filePath` does not exist.
|
|
611
|
+
- Error If the network request fails.
|
|
612
|
+
|
|
613
|
+
#### Example
|
|
614
|
+
|
|
615
|
+
```ts
|
|
616
|
+
const filePath = {
|
|
617
|
+
storageUnit: internalStorageUnit,
|
|
618
|
+
filePath: 'path/to/downloaded/file.zip',
|
|
619
|
+
};
|
|
620
|
+
const sourceUri = 'https://example.com/path/to/file.zip';
|
|
621
|
+
const headers = {
|
|
622
|
+
'Authorization': 'Bearer your_token_here',
|
|
623
|
+
};
|
|
624
|
+
await sos.fileSystem.downloadFile(filePath, sourceUri, headers);
|
|
625
|
+
```
|
|
245
626
|
|
|
246
627
|
<Separator />
|
|
247
628
|
|
|
@@ -252,48 +633,169 @@ The `exists()` method checks whether a file or directory exists.
|
|
|
252
633
|
```ts expandable
|
|
253
634
|
exists(filePath: IFilePath): Promise<boolean>;
|
|
254
635
|
// show-more
|
|
636
|
+
/**
|
|
637
|
+
* Base File System interface for methods.
|
|
638
|
+
*/
|
|
255
639
|
interface IFilePath {
|
|
640
|
+
/**
|
|
641
|
+
* Storage unit which is selected for performing file operations.
|
|
642
|
+
*/
|
|
256
643
|
storageUnit: IStorageUnit;
|
|
644
|
+
/**
|
|
645
|
+
* File path within the storage unit.
|
|
646
|
+
*/
|
|
257
647
|
filePath: string;
|
|
258
648
|
}
|
|
259
649
|
|
|
650
|
+
/**
|
|
651
|
+
* File System Storage Unit returned by the File System API.
|
|
652
|
+
*/
|
|
260
653
|
interface IStorageUnit {
|
|
654
|
+
/**
|
|
655
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
656
|
+
*/
|
|
261
657
|
type: string;
|
|
658
|
+
/**
|
|
659
|
+
* The total capacity of the storage unit in bytes.
|
|
660
|
+
*/
|
|
262
661
|
capacity: number;
|
|
662
|
+
/**
|
|
663
|
+
* The amount of free space available in the storage unit in bytes.
|
|
664
|
+
*/
|
|
263
665
|
freeSpace: number;
|
|
666
|
+
/**
|
|
667
|
+
* The amount of usable space in the storage unit in bytes.
|
|
668
|
+
*/
|
|
264
669
|
usableSpace: number;
|
|
670
|
+
/**
|
|
671
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
672
|
+
*/
|
|
265
673
|
removable: boolean;
|
|
266
674
|
}
|
|
267
675
|
|
|
268
676
|
```
|
|
269
677
|
|
|
678
|
+
#### Params
|
|
679
|
+
|
|
680
|
+
| Name | Type | Description |
|
|
681
|
+
|------------|-------------|---------------------------------------------|
|
|
682
|
+
| `filePath` | `IFilePath` | The path to the file or directory to check. |
|
|
683
|
+
|
|
684
|
+
#### Return value
|
|
685
|
+
|
|
686
|
+
A promise that resolves to `true` if the file or directory exists, `false` otherwise.
|
|
687
|
+
|
|
688
|
+
#### Possible errors
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
- Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
692
|
+
- Error If any error occurs during the existence check operation on the device.
|
|
693
|
+
|
|
694
|
+
#### Example
|
|
695
|
+
|
|
696
|
+
```ts
|
|
697
|
+
const filePath = {
|
|
698
|
+
storageUnit: internalStorageUnit,
|
|
699
|
+
filePath: 'path/to/file.txt',
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const fileExists = await sos.fileSystem.exists(filePath);
|
|
703
|
+
console.log(`File exists: ${fileExists}`); // Prints true if the file exists, false otherwise
|
|
704
|
+
```
|
|
705
|
+
|
|
270
706
|
<Separator />
|
|
271
707
|
|
|
272
708
|
### extractFile()
|
|
273
709
|
|
|
274
|
-
The `
|
|
710
|
+
The `extractFile()` method extract (recursively) the archive file at `archiveFilePath` into a new file specified by `destinationDirectoryPath`.
|
|
711
|
+
|
|
712
|
+
:::note
|
|
713
|
+
- The directory/folder you are extracting your ZIP file into has to be created BEFORE you start extracting the ZIP.
|
|
714
|
+
- Only supported extract method is `zip`.
|
|
715
|
+
:::
|
|
275
716
|
|
|
276
717
|
```ts expandable
|
|
277
|
-
extractFile(archiveFilePath: IFilePath, destinationDirectoryPath: IFilePath, method:
|
|
718
|
+
extractFile(archiveFilePath: IFilePath, destinationDirectoryPath: IFilePath, method: ExtractMethodType): Promise<void>;
|
|
278
719
|
// show-more
|
|
720
|
+
/**
|
|
721
|
+
* Base File System interface for methods.
|
|
722
|
+
*/
|
|
279
723
|
interface IFilePath {
|
|
724
|
+
/**
|
|
725
|
+
* Storage unit which is selected for performing file operations.
|
|
726
|
+
*/
|
|
280
727
|
storageUnit: IStorageUnit;
|
|
728
|
+
/**
|
|
729
|
+
* File path within the storage unit.
|
|
730
|
+
*/
|
|
281
731
|
filePath: string;
|
|
282
732
|
}
|
|
283
733
|
|
|
734
|
+
/**
|
|
735
|
+
* File System Storage Unit returned by the File System API.
|
|
736
|
+
*/
|
|
284
737
|
interface IStorageUnit {
|
|
738
|
+
/**
|
|
739
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
740
|
+
*/
|
|
285
741
|
type: string;
|
|
742
|
+
/**
|
|
743
|
+
* The total capacity of the storage unit in bytes.
|
|
744
|
+
*/
|
|
286
745
|
capacity: number;
|
|
746
|
+
/**
|
|
747
|
+
* The amount of free space available in the storage unit in bytes.
|
|
748
|
+
*/
|
|
287
749
|
freeSpace: number;
|
|
750
|
+
/**
|
|
751
|
+
* The amount of usable space in the storage unit in bytes.
|
|
752
|
+
*/
|
|
288
753
|
usableSpace: number;
|
|
754
|
+
/**
|
|
755
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
756
|
+
*/
|
|
289
757
|
removable: boolean;
|
|
290
758
|
}
|
|
291
759
|
|
|
760
|
+
/**
|
|
761
|
+
* Allowed extract method types for `extractFile()` operations.
|
|
762
|
+
*/
|
|
763
|
+
type ExtractMethodType = 'zip' | AnyString;
|
|
764
|
+
|
|
765
|
+
type AnyString = string & {};
|
|
766
|
+
|
|
292
767
|
```
|
|
293
768
|
|
|
769
|
+
#### Params
|
|
770
|
+
|
|
771
|
+
| Name | Type | Description |
|
|
772
|
+
|----------------------------|---------------------|-----------------------------------------------------------------------|
|
|
773
|
+
| `archiveFilePath` | `IFilePath` | The path to the archive file to be decompressed. |
|
|
774
|
+
| `destinationDirectoryPath` | `IFilePath` | The path to the directory where the decompressed files will be saved. |
|
|
775
|
+
| `method` | `ExtractMethodType` | Extract method to use for extracting, e.g. 'zip'. |
|
|
776
|
+
|
|
294
777
|
#### Possible errors
|
|
295
778
|
|
|
296
|
-
|
|
779
|
+
|
|
780
|
+
- Error If the archive file path does not exist.
|
|
781
|
+
- Error If it is not a valid archive file.
|
|
782
|
+
- Error If destination directory does not exist.
|
|
783
|
+
|
|
784
|
+
#### Example
|
|
785
|
+
|
|
786
|
+
```ts
|
|
787
|
+
const archiveFilePath = {
|
|
788
|
+
storageUnit: internalStorageUnit,
|
|
789
|
+
filePath: 'path/to/archive.zip',
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
const destinationDirectoryPath = {
|
|
793
|
+
storageUnit: internalStorageUnit,
|
|
794
|
+
filePath: 'path/to/destination/directory',
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
await sos.fileSystem.extractFile(archiveFilePath, destinationDirectoryPath, 'zip');
|
|
798
|
+
```
|
|
297
799
|
|
|
298
800
|
<Separator />
|
|
299
801
|
|
|
@@ -301,32 +803,108 @@ The method throws an error if the archive file path does not exist, it is not a
|
|
|
301
803
|
|
|
302
804
|
The `getFile()` method returns runtime information about a file path, such as local url, last modified date or size.
|
|
303
805
|
|
|
806
|
+
:::warning
|
|
807
|
+
Return statement is a dynamic object! It has to be always generated and retrieved by this JS API, as the values in localUri differ platform by platform. Never generate the object manually. `{"localUri":"file://internal/path/to/file.txt"}` is for demonstration only.
|
|
808
|
+
:::
|
|
809
|
+
|
|
304
810
|
```ts expandable
|
|
305
811
|
getFile(filePath: IFilePath): Promise<IFile | null>;
|
|
306
812
|
// show-more
|
|
813
|
+
/**
|
|
814
|
+
* Properties of returned file from File System API.
|
|
815
|
+
*/
|
|
816
|
+
interface IFile extends IFilePath {
|
|
817
|
+
localUri: string;
|
|
818
|
+
/**
|
|
819
|
+
* Image thumbnail URI of the file, which can be used to display a preview of the file.
|
|
820
|
+
* Note: Supported only on Linux.
|
|
821
|
+
*/
|
|
822
|
+
imageThumbnailUriTemplate?: string;
|
|
823
|
+
/**
|
|
824
|
+
* Video thumbnail URI of the file, which can be used to display a preview of the file.
|
|
825
|
+
* Note: Supported only on Linux.
|
|
826
|
+
*/
|
|
827
|
+
videoThumbnailUriTemplate?: string;
|
|
828
|
+
/**
|
|
829
|
+
* Date and time when the file was created in milliseconds since the epoch.
|
|
830
|
+
*/
|
|
831
|
+
createdAt?: number;
|
|
832
|
+
lastModifiedAt?: number;
|
|
833
|
+
sizeBytes?: number;
|
|
834
|
+
mimeType?: string;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Base File System interface for methods.
|
|
839
|
+
*/
|
|
307
840
|
interface IFilePath {
|
|
841
|
+
/**
|
|
842
|
+
* Storage unit which is selected for performing file operations.
|
|
843
|
+
*/
|
|
308
844
|
storageUnit: IStorageUnit;
|
|
845
|
+
/**
|
|
846
|
+
* File path within the storage unit.
|
|
847
|
+
*/
|
|
309
848
|
filePath: string;
|
|
310
849
|
}
|
|
311
850
|
|
|
851
|
+
/**
|
|
852
|
+
* File System Storage Unit returned by the File System API.
|
|
853
|
+
*/
|
|
312
854
|
interface IStorageUnit {
|
|
855
|
+
/**
|
|
856
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
857
|
+
*/
|
|
313
858
|
type: string;
|
|
859
|
+
/**
|
|
860
|
+
* The total capacity of the storage unit in bytes.
|
|
861
|
+
*/
|
|
314
862
|
capacity: number;
|
|
863
|
+
/**
|
|
864
|
+
* The amount of free space available in the storage unit in bytes.
|
|
865
|
+
*/
|
|
315
866
|
freeSpace: number;
|
|
867
|
+
/**
|
|
868
|
+
* The amount of usable space in the storage unit in bytes.
|
|
869
|
+
*/
|
|
316
870
|
usableSpace: number;
|
|
871
|
+
/**
|
|
872
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
873
|
+
*/
|
|
317
874
|
removable: boolean;
|
|
318
875
|
}
|
|
319
876
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
#### Params
|
|
880
|
+
|
|
881
|
+
| Name | Type | Description |
|
|
882
|
+
|------------|-------------|---------------------------------------|
|
|
883
|
+
| `filePath` | `IFilePath` | The path to the file to be retrieved. |
|
|
884
|
+
|
|
885
|
+
#### Return value
|
|
886
|
+
|
|
887
|
+
A promise that resolves to the file information or `null` if the file does not exist.
|
|
329
888
|
|
|
889
|
+
#### Possible errors
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
- Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
893
|
+
- Error If the file is a directory.
|
|
894
|
+
- Error If any error occurs during the retrieval operation on the device.
|
|
895
|
+
|
|
896
|
+
#### Example
|
|
897
|
+
|
|
898
|
+
```ts
|
|
899
|
+
// Get file information
|
|
900
|
+
const filePath = {
|
|
901
|
+
storageUnit: internalStorageUnit,
|
|
902
|
+
filePath: 'path/to/file.txt',
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
const fileInfo = await sos.fileSystem.getFile(filePath);
|
|
906
|
+
console.log(JSON.stringify(fileInfo)); // Prints the file information
|
|
907
|
+
console.log(fileInfo.localUri); // Prints the local URI of the file
|
|
330
908
|
```
|
|
331
909
|
|
|
332
910
|
<Separator />
|
|
@@ -335,31 +913,93 @@ interface IFile extends IFilePath {
|
|
|
335
913
|
|
|
336
914
|
The `getChecksumFile()` method computes a checksum of the file specified by `filePath`.
|
|
337
915
|
|
|
916
|
+
:::warning Tizen limitation
|
|
917
|
+
If you are about to use the MD5 file validation it will automatically return on any Samsung Tizen - 2.4, 3.0 and 4.0.
|
|
918
|
+
Reason: MD5 file checksum is not available on any Tizen displays due to the Samsung restriction.
|
|
919
|
+
:::
|
|
920
|
+
|
|
338
921
|
```ts expandable
|
|
339
922
|
getFileChecksum(filePath: IFilePath, hashType: HashAlgorithm): Promise<string>;
|
|
340
923
|
// show-more
|
|
924
|
+
/**
|
|
925
|
+
* Base File System interface for methods.
|
|
926
|
+
*/
|
|
341
927
|
interface IFilePath {
|
|
928
|
+
/**
|
|
929
|
+
* Storage unit which is selected for performing file operations.
|
|
930
|
+
*/
|
|
342
931
|
storageUnit: IStorageUnit;
|
|
932
|
+
/**
|
|
933
|
+
* File path within the storage unit.
|
|
934
|
+
*/
|
|
343
935
|
filePath: string;
|
|
344
936
|
}
|
|
345
937
|
|
|
938
|
+
/**
|
|
939
|
+
* File System Storage Unit returned by the File System API.
|
|
940
|
+
*/
|
|
346
941
|
interface IStorageUnit {
|
|
942
|
+
/**
|
|
943
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
944
|
+
*/
|
|
347
945
|
type: string;
|
|
946
|
+
/**
|
|
947
|
+
* The total capacity of the storage unit in bytes.
|
|
948
|
+
*/
|
|
348
949
|
capacity: number;
|
|
950
|
+
/**
|
|
951
|
+
* The amount of free space available in the storage unit in bytes.
|
|
952
|
+
*/
|
|
349
953
|
freeSpace: number;
|
|
954
|
+
/**
|
|
955
|
+
* The amount of usable space in the storage unit in bytes.
|
|
956
|
+
*/
|
|
350
957
|
usableSpace: number;
|
|
958
|
+
/**
|
|
959
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
960
|
+
*/
|
|
351
961
|
removable: boolean;
|
|
352
962
|
}
|
|
353
963
|
|
|
354
|
-
|
|
964
|
+
/**
|
|
965
|
+
* Represents the supported hash algorithms by Core Apps.
|
|
966
|
+
*/
|
|
967
|
+
type HashAlgorithm = 'md5' | 'crc32' | AnyString;
|
|
355
968
|
|
|
356
969
|
type AnyString = string & {};
|
|
357
970
|
|
|
358
971
|
```
|
|
359
972
|
|
|
973
|
+
#### Params
|
|
974
|
+
|
|
975
|
+
| Name | Type | Description |
|
|
976
|
+
|------------|-----------------|---------------------------------------------------------------|
|
|
977
|
+
| `filePath` | `IFilePath` | The path to the file for which the checksum will be computed. |
|
|
978
|
+
| `hashType` | `HashAlgorithm` | The type of hash algorithm to use for computing the checksum. |
|
|
979
|
+
|
|
980
|
+
#### Return value
|
|
981
|
+
|
|
982
|
+
A promise that resolves to the computed checksum of the file.
|
|
983
|
+
|
|
360
984
|
#### Possible errors
|
|
361
985
|
|
|
362
|
-
|
|
986
|
+
|
|
987
|
+
- Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
988
|
+
- Error If `hashType` is not a valid type or string.
|
|
989
|
+
- Error If the file does not exist.
|
|
990
|
+
- Error If `filepath` it is a directory
|
|
991
|
+
|
|
992
|
+
#### Example
|
|
993
|
+
|
|
994
|
+
```ts
|
|
995
|
+
const filePath = {
|
|
996
|
+
storageUnit: internalStorageUnit,
|
|
997
|
+
filePath: 'path/to/file.txt',
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
const checksum = await sos.fileSystem.getFileChecksum(filePath, 'md5');
|
|
1001
|
+
console.log(`Checksum of the file: ${checksum}`);
|
|
1002
|
+
```
|
|
363
1003
|
|
|
364
1004
|
<Separator />
|
|
365
1005
|
|
|
@@ -370,49 +1010,169 @@ The `isDirectory()` method checks whether the file path points to a directory.
|
|
|
370
1010
|
```ts expandable
|
|
371
1011
|
isDirectory(filePath: IFilePath): Promise<boolean>;
|
|
372
1012
|
// show-more
|
|
1013
|
+
/**
|
|
1014
|
+
* Base File System interface for methods.
|
|
1015
|
+
*/
|
|
373
1016
|
interface IFilePath {
|
|
1017
|
+
/**
|
|
1018
|
+
* Storage unit which is selected for performing file operations.
|
|
1019
|
+
*/
|
|
374
1020
|
storageUnit: IStorageUnit;
|
|
1021
|
+
/**
|
|
1022
|
+
* File path within the storage unit.
|
|
1023
|
+
*/
|
|
375
1024
|
filePath: string;
|
|
376
1025
|
}
|
|
377
1026
|
|
|
1027
|
+
/**
|
|
1028
|
+
* File System Storage Unit returned by the File System API.
|
|
1029
|
+
*/
|
|
378
1030
|
interface IStorageUnit {
|
|
1031
|
+
/**
|
|
1032
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1033
|
+
*/
|
|
379
1034
|
type: string;
|
|
1035
|
+
/**
|
|
1036
|
+
* The total capacity of the storage unit in bytes.
|
|
1037
|
+
*/
|
|
380
1038
|
capacity: number;
|
|
1039
|
+
/**
|
|
1040
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1041
|
+
*/
|
|
381
1042
|
freeSpace: number;
|
|
1043
|
+
/**
|
|
1044
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1045
|
+
*/
|
|
382
1046
|
usableSpace: number;
|
|
1047
|
+
/**
|
|
1048
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1049
|
+
*/
|
|
383
1050
|
removable: boolean;
|
|
384
1051
|
}
|
|
385
1052
|
|
|
386
1053
|
```
|
|
387
1054
|
|
|
1055
|
+
#### Params
|
|
1056
|
+
|
|
1057
|
+
| Name | Type | Description |
|
|
1058
|
+
|------------|-------------|-------------------------|
|
|
1059
|
+
| `filePath` | `IFilePath` | The file path to check. |
|
|
1060
|
+
|
|
1061
|
+
#### Return value
|
|
1062
|
+
|
|
1063
|
+
A promise that resolves to `true` if the file path is a directory, `false` otherwise.
|
|
1064
|
+
|
|
388
1065
|
#### Possible errors
|
|
389
1066
|
|
|
390
|
-
|
|
1067
|
+
|
|
1068
|
+
- Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
1069
|
+
- Error If the file path does not exist.
|
|
1070
|
+
|
|
1071
|
+
#### Example
|
|
1072
|
+
|
|
1073
|
+
```ts
|
|
1074
|
+
const filePath = {
|
|
1075
|
+
storageUnit: internalStorageUnit,
|
|
1076
|
+
filePath: 'path/to/directory',
|
|
1077
|
+
};
|
|
1078
|
+
const isDir = await sos.fileSystem.isDirectory(filePath);
|
|
1079
|
+
if (isDir) {
|
|
1080
|
+
console.log('The file path is a directory.');
|
|
1081
|
+
} else {
|
|
1082
|
+
console.log('The file path is not a directory.');
|
|
1083
|
+
}
|
|
1084
|
+
```
|
|
391
1085
|
|
|
392
1086
|
<Separator />
|
|
393
1087
|
|
|
394
1088
|
### link()
|
|
395
1089
|
|
|
396
|
-
The `link()` method creates a symbolic link
|
|
1090
|
+
The `link()` method creates a symbolic link from `sourceFilePath` (existing path) to `destinationFilePath` (new path).
|
|
1091
|
+
|
|
1092
|
+
:::note
|
|
1093
|
+
This method is only available on Linux devices.
|
|
1094
|
+
:::
|
|
397
1095
|
|
|
398
1096
|
```ts expandable
|
|
399
1097
|
link(sourceFilePath: IFilePath, destinationFilePath: IFilePath): Promise<void>;
|
|
400
1098
|
// show-more
|
|
1099
|
+
/**
|
|
1100
|
+
* Base File System interface for methods.
|
|
1101
|
+
*/
|
|
401
1102
|
interface IFilePath {
|
|
1103
|
+
/**
|
|
1104
|
+
* Storage unit which is selected for performing file operations.
|
|
1105
|
+
*/
|
|
402
1106
|
storageUnit: IStorageUnit;
|
|
1107
|
+
/**
|
|
1108
|
+
* File path within the storage unit.
|
|
1109
|
+
*/
|
|
403
1110
|
filePath: string;
|
|
404
1111
|
}
|
|
405
1112
|
|
|
1113
|
+
/**
|
|
1114
|
+
* File System Storage Unit returned by the File System API.
|
|
1115
|
+
*/
|
|
406
1116
|
interface IStorageUnit {
|
|
1117
|
+
/**
|
|
1118
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1119
|
+
*/
|
|
407
1120
|
type: string;
|
|
1121
|
+
/**
|
|
1122
|
+
* The total capacity of the storage unit in bytes.
|
|
1123
|
+
*/
|
|
408
1124
|
capacity: number;
|
|
1125
|
+
/**
|
|
1126
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1127
|
+
*/
|
|
409
1128
|
freeSpace: number;
|
|
1129
|
+
/**
|
|
1130
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1131
|
+
*/
|
|
410
1132
|
usableSpace: number;
|
|
1133
|
+
/**
|
|
1134
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1135
|
+
*/
|
|
411
1136
|
removable: boolean;
|
|
412
1137
|
}
|
|
413
1138
|
|
|
414
1139
|
```
|
|
415
1140
|
|
|
1141
|
+
#### Params
|
|
1142
|
+
|
|
1143
|
+
| Name | Type | Description |
|
|
1144
|
+
|-----------------------|-------------|----------------------------------------------------------------------|
|
|
1145
|
+
| `sourceFilePath` | `IFilePath` | The path to the existing file or directory that you want to link to. |
|
|
1146
|
+
| `destinationFilePath` | `IFilePath` | The path where the symbolic link will be created. |
|
|
1147
|
+
|
|
1148
|
+
#### Return value
|
|
1149
|
+
|
|
1150
|
+
A promise that resolves when the symbolic link is created successfully.
|
|
1151
|
+
|
|
1152
|
+
#### Possible errors
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
- Error If `sourceFilePath` or `destinationPath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
1156
|
+
- Error If the `sourceFilePath` does not exist or if the `destinationFilePath` already exists.
|
|
1157
|
+
- Error The platform does not support linking directories.
|
|
1158
|
+
|
|
1159
|
+
#### Example
|
|
1160
|
+
|
|
1161
|
+
```ts
|
|
1162
|
+
const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
|
|
1163
|
+
const sourceFilePath = {
|
|
1164
|
+
storageUnit: internalStorageUnit,
|
|
1165
|
+
filePath: 'path/to/existing/file.txt',
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1168
|
+
const destinationFilePath = {
|
|
1169
|
+
storageUnit: internalStorageUnit,
|
|
1170
|
+
filePath: 'path/to/symlink/file_link.txt',
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
await sos.fileSystem.link(sourceFilePath, destinationFilePath);
|
|
1174
|
+
```
|
|
1175
|
+
|
|
416
1176
|
<Separator />
|
|
417
1177
|
|
|
418
1178
|
### listFiles()
|
|
@@ -422,24 +1182,80 @@ The `listFiles()` method lists all files and directories in the specified path (
|
|
|
422
1182
|
```ts expandable
|
|
423
1183
|
listFiles(directoryPath: IFilePath): Promise<IFilePath[]>;
|
|
424
1184
|
// show-more
|
|
1185
|
+
/**
|
|
1186
|
+
* Base File System interface for methods.
|
|
1187
|
+
*/
|
|
425
1188
|
interface IFilePath {
|
|
1189
|
+
/**
|
|
1190
|
+
* Storage unit which is selected for performing file operations.
|
|
1191
|
+
*/
|
|
426
1192
|
storageUnit: IStorageUnit;
|
|
1193
|
+
/**
|
|
1194
|
+
* File path within the storage unit.
|
|
1195
|
+
*/
|
|
427
1196
|
filePath: string;
|
|
428
1197
|
}
|
|
429
1198
|
|
|
1199
|
+
/**
|
|
1200
|
+
* File System Storage Unit returned by the File System API.
|
|
1201
|
+
*/
|
|
430
1202
|
interface IStorageUnit {
|
|
1203
|
+
/**
|
|
1204
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1205
|
+
*/
|
|
431
1206
|
type: string;
|
|
1207
|
+
/**
|
|
1208
|
+
* The total capacity of the storage unit in bytes.
|
|
1209
|
+
*/
|
|
432
1210
|
capacity: number;
|
|
1211
|
+
/**
|
|
1212
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1213
|
+
*/
|
|
433
1214
|
freeSpace: number;
|
|
1215
|
+
/**
|
|
1216
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1217
|
+
*/
|
|
434
1218
|
usableSpace: number;
|
|
1219
|
+
/**
|
|
1220
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1221
|
+
*/
|
|
435
1222
|
removable: boolean;
|
|
436
1223
|
}
|
|
437
1224
|
|
|
438
1225
|
```
|
|
439
1226
|
|
|
1227
|
+
#### Params
|
|
1228
|
+
|
|
1229
|
+
| Name | Type | Description |
|
|
1230
|
+
|-----------------|-------------|-------------------------------------------------------|
|
|
1231
|
+
| `directoryPath` | `IFilePath` | The path to the directory where files will be listed. |
|
|
1232
|
+
|
|
1233
|
+
#### Return value
|
|
1234
|
+
|
|
1235
|
+
A promise that resolves to an array of file paths in the specified directory.
|
|
1236
|
+
|
|
440
1237
|
#### Possible errors
|
|
441
1238
|
|
|
442
|
-
|
|
1239
|
+
|
|
1240
|
+
- Error If `directoryPath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
1241
|
+
- Error If the path does not exist, or it is a file.
|
|
1242
|
+
|
|
1243
|
+
#### Example
|
|
1244
|
+
|
|
1245
|
+
```ts
|
|
1246
|
+
// List files in the root directory of the internal storage unit
|
|
1247
|
+
const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
|
|
1248
|
+
const directoryPath = {
|
|
1249
|
+
storageUnit: internalStorageUnit,
|
|
1250
|
+
filePath: '', // Empty string is used as an absolute path instead of "/"
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
const files = await sos.fileSystem.listFiles(directoryPath);
|
|
1254
|
+
console.log('Files in the root directory:', files.length);
|
|
1255
|
+
files.forEach((file) => {
|
|
1256
|
+
console.log(`File: ${file.filePath}`);
|
|
1257
|
+
});
|
|
1258
|
+
```
|
|
443
1259
|
|
|
444
1260
|
<Separator />
|
|
445
1261
|
|
|
@@ -450,16 +1266,51 @@ A shorthand method for listing only the internal storage units (i.e. those with
|
|
|
450
1266
|
```ts expandable
|
|
451
1267
|
listInternalStorageUnits(): Promise<IStorageUnit[]>;
|
|
452
1268
|
// show-more
|
|
1269
|
+
/**
|
|
1270
|
+
* File System Storage Unit returned by the File System API.
|
|
1271
|
+
*/
|
|
453
1272
|
interface IStorageUnit {
|
|
1273
|
+
/**
|
|
1274
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1275
|
+
*/
|
|
454
1276
|
type: string;
|
|
1277
|
+
/**
|
|
1278
|
+
* The total capacity of the storage unit in bytes.
|
|
1279
|
+
*/
|
|
455
1280
|
capacity: number;
|
|
1281
|
+
/**
|
|
1282
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1283
|
+
*/
|
|
456
1284
|
freeSpace: number;
|
|
1285
|
+
/**
|
|
1286
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1287
|
+
*/
|
|
457
1288
|
usableSpace: number;
|
|
1289
|
+
/**
|
|
1290
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1291
|
+
*/
|
|
458
1292
|
removable: boolean;
|
|
459
1293
|
}
|
|
460
1294
|
|
|
461
1295
|
```
|
|
462
1296
|
|
|
1297
|
+
#### Return value
|
|
1298
|
+
|
|
1299
|
+
An array of internal storage units available on the device.
|
|
1300
|
+
|
|
1301
|
+
#### Example
|
|
1302
|
+
|
|
1303
|
+
```ts
|
|
1304
|
+
// List internal storage units
|
|
1305
|
+
const internalStorageUnits = await sos.fileSystem.listInternalStorageUnits();
|
|
1306
|
+
internalStorageUnits.forEach((storageUnit) => {
|
|
1307
|
+
console.log(`Storage Unit Type: ${storageUnit.type}`);
|
|
1308
|
+
console.log(`Capacity: ${storageUnit.capacity} bytes`);
|
|
1309
|
+
console.log(`Free Space: ${storageUnit.freeSpace} bytes`);
|
|
1310
|
+
console.log(`Usable Space: ${storageUnit.usableSpace} bytes`);
|
|
1311
|
+
});
|
|
1312
|
+
```
|
|
1313
|
+
|
|
463
1314
|
<Separator />
|
|
464
1315
|
|
|
465
1316
|
### listStorageUnits()
|
|
@@ -467,19 +1318,65 @@ interface IStorageUnit {
|
|
|
467
1318
|
The `listStorageUnits()` method lists all available storage units. All devices always have one internal storage device (with
|
|
468
1319
|
`removable: false`) and zero or more external devices. The capacity values are in bytes.
|
|
469
1320
|
|
|
1321
|
+
:::note
|
|
1322
|
+
This is a mandatory method that is required for all the other File System APIs. The other APIs require a storageUnit object that is retrieved from this method to manipulate with files on a correct storage location (internal/external).
|
|
1323
|
+
:::
|
|
1324
|
+
|
|
1325
|
+
:::warning
|
|
1326
|
+
`storageUnit` is a dynamic object! It has to be always generated and retrieved by this JS API, as the values in type differ platform by platform. Never generate the object manually. `{"type":"internal"}` is for demonstration only.
|
|
1327
|
+
:::
|
|
1328
|
+
|
|
470
1329
|
```ts expandable
|
|
471
1330
|
listStorageUnits(): Promise<IStorageUnit[]>;
|
|
472
1331
|
// show-more
|
|
1332
|
+
/**
|
|
1333
|
+
* File System Storage Unit returned by the File System API.
|
|
1334
|
+
*/
|
|
473
1335
|
interface IStorageUnit {
|
|
1336
|
+
/**
|
|
1337
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1338
|
+
*/
|
|
474
1339
|
type: string;
|
|
1340
|
+
/**
|
|
1341
|
+
* The total capacity of the storage unit in bytes.
|
|
1342
|
+
*/
|
|
475
1343
|
capacity: number;
|
|
1344
|
+
/**
|
|
1345
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1346
|
+
*/
|
|
476
1347
|
freeSpace: number;
|
|
1348
|
+
/**
|
|
1349
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1350
|
+
*/
|
|
477
1351
|
usableSpace: number;
|
|
1352
|
+
/**
|
|
1353
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1354
|
+
*/
|
|
478
1355
|
removable: boolean;
|
|
479
1356
|
}
|
|
480
1357
|
|
|
481
1358
|
```
|
|
482
1359
|
|
|
1360
|
+
#### Return value
|
|
1361
|
+
|
|
1362
|
+
An array of storage units available on the device.
|
|
1363
|
+
|
|
1364
|
+
#### Possible errors
|
|
1365
|
+
|
|
1366
|
+
InternalFileSystemError Unexpected error occurred when listing storage units.
|
|
1367
|
+
|
|
1368
|
+
#### Example
|
|
1369
|
+
|
|
1370
|
+
```ts
|
|
1371
|
+
// Storage units are equivalent to disk volumes (C:, D: etc on Windows; /mnt/disc1, /mnt/disc2 on Unix)
|
|
1372
|
+
const storageUnits = await sos.fileSystem.listStorageUnits();
|
|
1373
|
+
const externalStorageUnits = storageUnits.filter((storageUnit) => storageUnit.removable);
|
|
1374
|
+
externalStorageUnits.forEach((storageUnit) => {
|
|
1375
|
+
console.log(`Storage Unit Type: ${storageUnit.type}`);
|
|
1376
|
+
console.log(`Capacity: ${storageUnit.capacity} bytes`);
|
|
1377
|
+
});
|
|
1378
|
+
```
|
|
1379
|
+
|
|
483
1380
|
<Separator />
|
|
484
1381
|
|
|
485
1382
|
### moveFile()
|
|
@@ -489,16 +1386,43 @@ The `moveFile()` method moves a file from `sourceFilePath` to `destinationFilePa
|
|
|
489
1386
|
```ts expandable
|
|
490
1387
|
moveFile(sourceFilePath: IFilePath, destinationFilePath: IFilePath, options?: IMoveFileOptions): Promise<void>;
|
|
491
1388
|
// show-more
|
|
1389
|
+
/**
|
|
1390
|
+
* Base File System interface for methods.
|
|
1391
|
+
*/
|
|
492
1392
|
interface IFilePath {
|
|
1393
|
+
/**
|
|
1394
|
+
* Storage unit which is selected for performing file operations.
|
|
1395
|
+
*/
|
|
493
1396
|
storageUnit: IStorageUnit;
|
|
1397
|
+
/**
|
|
1398
|
+
* File path within the storage unit.
|
|
1399
|
+
*/
|
|
494
1400
|
filePath: string;
|
|
495
1401
|
}
|
|
496
1402
|
|
|
1403
|
+
/**
|
|
1404
|
+
* File System Storage Unit returned by the File System API.
|
|
1405
|
+
*/
|
|
497
1406
|
interface IStorageUnit {
|
|
1407
|
+
/**
|
|
1408
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1409
|
+
*/
|
|
498
1410
|
type: string;
|
|
1411
|
+
/**
|
|
1412
|
+
* The total capacity of the storage unit in bytes.
|
|
1413
|
+
*/
|
|
499
1414
|
capacity: number;
|
|
1415
|
+
/**
|
|
1416
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1417
|
+
*/
|
|
500
1418
|
freeSpace: number;
|
|
1419
|
+
/**
|
|
1420
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1421
|
+
*/
|
|
501
1422
|
usableSpace: number;
|
|
1423
|
+
/**
|
|
1424
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1425
|
+
*/
|
|
502
1426
|
removable: boolean;
|
|
503
1427
|
}
|
|
504
1428
|
|
|
@@ -508,10 +1432,43 @@ interface IMoveFileOptions {
|
|
|
508
1432
|
|
|
509
1433
|
```
|
|
510
1434
|
|
|
1435
|
+
#### Params
|
|
1436
|
+
|
|
1437
|
+
| Name | Type | Description |
|
|
1438
|
+
|----------------------------------|--------------------|----------------------------------------------------------------------------------------|
|
|
1439
|
+
| `sourceFilePath` | `IFilePath` | The path to the file to be moved. |
|
|
1440
|
+
| `destinationFilePath` | `IFilePath` | The path where the file will be moved to. |
|
|
1441
|
+
| `options` *(optional)* | `IMoveFileOptions` | Options for moving the file. |
|
|
1442
|
+
| `options.overwrite` *(optional)* | `boolean` | If set to `true`, the method will overwrite the destination file if it already exists. |
|
|
1443
|
+
|
|
1444
|
+
#### Return value
|
|
1445
|
+
|
|
1446
|
+
A promise that resolves when the file is moved successfully.
|
|
1447
|
+
|
|
511
1448
|
#### Possible errors
|
|
512
1449
|
|
|
513
|
-
|
|
514
|
-
|
|
1450
|
+
|
|
1451
|
+
- Error If the source file does not exist or parent of the destination file path does not exist.
|
|
1452
|
+
- Error If the `options.overwrite` is not set and the destination file path already exists.
|
|
1453
|
+
- Error If deleting path does not exist.
|
|
1454
|
+
- Error If any error occurs during the move operation on the device.
|
|
1455
|
+
|
|
1456
|
+
#### Example
|
|
1457
|
+
|
|
1458
|
+
```ts
|
|
1459
|
+
// Move file from one directory to another and overwrite it if it already exists
|
|
1460
|
+
const sourceFilePath = {
|
|
1461
|
+
storageUnit: internalStorageUnit,
|
|
1462
|
+
filePath: 'path/to/source/file.txt',
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
const destinationFilePath = {
|
|
1466
|
+
storageUnit: internalStorageUnit,
|
|
1467
|
+
filePath: 'path/to/destination/file.txt',
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
await sos.fileSystem.moveFile(sourceFilePath, destinationFilePath, { overwrite: true });
|
|
1471
|
+
```
|
|
515
1472
|
|
|
516
1473
|
<Separator />
|
|
517
1474
|
|
|
@@ -523,40 +1480,103 @@ The `onStorageUnitsChanged()` method sets up a listener, which is called wheneve
|
|
|
523
1480
|
onStorageUnitsChanged(listener: () => void): void;
|
|
524
1481
|
```
|
|
525
1482
|
|
|
1483
|
+
#### Params
|
|
1484
|
+
|
|
1485
|
+
| Name | Type | Description |
|
|
1486
|
+
|------------|--------------|-------------------------------------------------------------------|
|
|
1487
|
+
| `listener` | `() => void` | The listener function to be called when the storage units change. |
|
|
1488
|
+
|
|
1489
|
+
#### Possible errors
|
|
1490
|
+
|
|
1491
|
+
Error If `listener` is not a valid function.
|
|
1492
|
+
|
|
526
1493
|
<Separator />
|
|
527
1494
|
|
|
528
1495
|
### readFile()
|
|
529
1496
|
|
|
530
|
-
The `readFile()` method returns content of the file specified by `filePath`.
|
|
531
|
-
mangled.
|
|
1497
|
+
The `readFile()` method returns content of the file specified by `filePath`.
|
|
1498
|
+
The file has to be a text file, otherwise the content will be mangled.
|
|
532
1499
|
|
|
533
1500
|
```ts expandable
|
|
534
1501
|
readFile(filePath: IFilePath): Promise<string>;
|
|
535
1502
|
// show-more
|
|
1503
|
+
/**
|
|
1504
|
+
* Base File System interface for methods.
|
|
1505
|
+
*/
|
|
536
1506
|
interface IFilePath {
|
|
1507
|
+
/**
|
|
1508
|
+
* Storage unit which is selected for performing file operations.
|
|
1509
|
+
*/
|
|
537
1510
|
storageUnit: IStorageUnit;
|
|
1511
|
+
/**
|
|
1512
|
+
* File path within the storage unit.
|
|
1513
|
+
*/
|
|
538
1514
|
filePath: string;
|
|
539
1515
|
}
|
|
540
1516
|
|
|
1517
|
+
/**
|
|
1518
|
+
* File System Storage Unit returned by the File System API.
|
|
1519
|
+
*/
|
|
541
1520
|
interface IStorageUnit {
|
|
1521
|
+
/**
|
|
1522
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1523
|
+
*/
|
|
542
1524
|
type: string;
|
|
1525
|
+
/**
|
|
1526
|
+
* The total capacity of the storage unit in bytes.
|
|
1527
|
+
*/
|
|
543
1528
|
capacity: number;
|
|
1529
|
+
/**
|
|
1530
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1531
|
+
*/
|
|
544
1532
|
freeSpace: number;
|
|
1533
|
+
/**
|
|
1534
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1535
|
+
*/
|
|
545
1536
|
usableSpace: number;
|
|
1537
|
+
/**
|
|
1538
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1539
|
+
*/
|
|
546
1540
|
removable: boolean;
|
|
547
1541
|
}
|
|
548
1542
|
|
|
549
1543
|
```
|
|
550
1544
|
|
|
1545
|
+
#### Params
|
|
1546
|
+
|
|
1547
|
+
| Name | Type | Description |
|
|
1548
|
+
|------------|-------------|----------------------------------|
|
|
1549
|
+
| `filePath` | `IFilePath` | The path to the file to be read. |
|
|
1550
|
+
|
|
1551
|
+
#### Return value
|
|
1552
|
+
|
|
1553
|
+
A promise that resolves to the content of the file.
|
|
1554
|
+
|
|
551
1555
|
#### Possible errors
|
|
552
1556
|
|
|
553
|
-
|
|
1557
|
+
|
|
1558
|
+
- Error If the file does not exist.
|
|
1559
|
+
- Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
1560
|
+
- Error If the file is a directory.
|
|
1561
|
+
- Error If any error occurs during the read operation on the device.
|
|
1562
|
+
|
|
1563
|
+
#### Example
|
|
1564
|
+
|
|
1565
|
+
```ts
|
|
1566
|
+
const filePath = {
|
|
1567
|
+
storageUnit: internalStorageUnit,
|
|
1568
|
+
filePath: 'path/to/file.txt',
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const fileContent = await sos.fileSystem.readFile(filePath);
|
|
1572
|
+
console.log(`Content of the file: ${fileContent}`);
|
|
1573
|
+
```
|
|
554
1574
|
|
|
555
1575
|
<Separator />
|
|
556
1576
|
|
|
557
1577
|
### removeAllListeners()
|
|
558
1578
|
|
|
559
|
-
The `removeAllListeners()` method removes all listeners, previously added by `
|
|
1579
|
+
The `removeAllListeners()` method removes all listeners, previously added by `onStorageUnitsChanged()`
|
|
560
1580
|
|
|
561
1581
|
```ts expandable
|
|
562
1582
|
removeAllListeners(): void;
|
|
@@ -578,43 +1598,99 @@ removeStorageUnitsChangedListener(listener: () => void): void;
|
|
|
578
1598
|
|
|
579
1599
|
The `wipeout()` method is used to wipe out all data from the file system, later when action is finished the device is rebooted.
|
|
580
1600
|
|
|
1601
|
+
```ts expandable
|
|
1602
|
+
wipeout(): Promise<void>;
|
|
1603
|
+
```
|
|
1604
|
+
|
|
1605
|
+
#### Return value
|
|
1606
|
+
|
|
1607
|
+
A promise that resolves when the wipeout is complete.
|
|
1608
|
+
|
|
581
1609
|
:::danger
|
|
582
1610
|
- Ensure that function is called only once, otherwise it will wipe out the file system again on applet start!
|
|
583
1611
|
- This function is clearing internal file system storage, cache storage and cookies. Local storage will not be cleared.
|
|
584
1612
|
:::
|
|
585
1613
|
|
|
586
|
-
```ts expandable
|
|
587
|
-
wipeout(): Promise<void>;
|
|
588
|
-
```
|
|
589
|
-
|
|
590
1614
|
<Separator />
|
|
591
1615
|
|
|
592
1616
|
### writeFile()
|
|
593
1617
|
|
|
594
|
-
The `writeFile()` method writes string content to the file specified by `filePath`. If the file does exist, it is created.
|
|
595
|
-
does not exist, an error is thrown.
|
|
1618
|
+
The `writeFile()` method writes string content to the file specified by `filePath`. If the file does exist, it is created.
|
|
596
1619
|
|
|
597
1620
|
```ts expandable
|
|
598
1621
|
writeFile(filePath: IFilePath, contents: string): Promise<void>;
|
|
599
1622
|
// show-more
|
|
1623
|
+
/**
|
|
1624
|
+
* Base File System interface for methods.
|
|
1625
|
+
*/
|
|
600
1626
|
interface IFilePath {
|
|
1627
|
+
/**
|
|
1628
|
+
* Storage unit which is selected for performing file operations.
|
|
1629
|
+
*/
|
|
601
1630
|
storageUnit: IStorageUnit;
|
|
1631
|
+
/**
|
|
1632
|
+
* File path within the storage unit.
|
|
1633
|
+
*/
|
|
602
1634
|
filePath: string;
|
|
603
1635
|
}
|
|
604
1636
|
|
|
1637
|
+
/**
|
|
1638
|
+
* File System Storage Unit returned by the File System API.
|
|
1639
|
+
*/
|
|
605
1640
|
interface IStorageUnit {
|
|
1641
|
+
/**
|
|
1642
|
+
* The type of the storage unit, e.g., "internal" or "external".
|
|
1643
|
+
*/
|
|
606
1644
|
type: string;
|
|
1645
|
+
/**
|
|
1646
|
+
* The total capacity of the storage unit in bytes.
|
|
1647
|
+
*/
|
|
607
1648
|
capacity: number;
|
|
1649
|
+
/**
|
|
1650
|
+
* The amount of free space available in the storage unit in bytes.
|
|
1651
|
+
*/
|
|
608
1652
|
freeSpace: number;
|
|
1653
|
+
/**
|
|
1654
|
+
* The amount of usable space in the storage unit in bytes.
|
|
1655
|
+
*/
|
|
609
1656
|
usableSpace: number;
|
|
1657
|
+
/**
|
|
1658
|
+
* Indicates whether the storage unit is removable (e.g., an SD card).
|
|
1659
|
+
*/
|
|
610
1660
|
removable: boolean;
|
|
611
1661
|
}
|
|
612
1662
|
|
|
613
1663
|
```
|
|
614
1664
|
|
|
1665
|
+
#### Params
|
|
1666
|
+
|
|
1667
|
+
| Name | Type | Description |
|
|
1668
|
+
|------------|-------------|----------------------------------------|
|
|
1669
|
+
| `filePath` | `IFilePath` | The path to the file to be written. |
|
|
1670
|
+
| `contents` | `string` | The content to be written to the file. |
|
|
1671
|
+
|
|
1672
|
+
#### Return value
|
|
1673
|
+
|
|
1674
|
+
A promise that resolves when the content is written successfully.
|
|
1675
|
+
|
|
615
1676
|
#### Possible errors
|
|
616
1677
|
|
|
617
|
-
|
|
1678
|
+
|
|
1679
|
+
- Error If the parent directory does not exist or the `filePath` is a directory.
|
|
1680
|
+
- Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
|
|
1681
|
+
- Error If any error occurs during the write operation on the device.
|
|
1682
|
+
|
|
1683
|
+
#### Example
|
|
1684
|
+
|
|
1685
|
+
```ts
|
|
1686
|
+
const filePath = {
|
|
1687
|
+
storageUnit: internalStorageUnit,
|
|
1688
|
+
filePath: 'path/to/file.txt',
|
|
1689
|
+
};
|
|
1690
|
+
|
|
1691
|
+
const contents = 'This is the content to write to the file.';
|
|
1692
|
+
await sos.fileSystem.writeFile(filePath, contents);
|
|
1693
|
+
```
|
|
618
1694
|
|
|
619
1695
|
## API Example
|
|
620
1696
|
|