@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.
Files changed (74) hide show
  1. package/dist/bundle.js +1 -1
  2. package/dist/bundle.js.map +1 -1
  3. package/docs/sos/browser.md +66 -14
  4. package/docs/sos/command.md +52 -6
  5. package/docs/sos/debug.md +17 -2
  6. package/docs/sos/deviceInfo.md +27 -0
  7. package/docs/sos/display.md +34 -3
  8. package/docs/sos/fileSystem.md +1135 -59
  9. package/docs/sos/index.md +36 -12
  10. package/docs/sos/input.md +42 -1
  11. package/docs/sos/native/mdc.md +65 -19
  12. package/docs/sos/offline/cache.md +14 -8
  13. package/docs/sos/stream.md +1172 -37
  14. package/docs/sos/sync.md +2 -2
  15. package/docs/sos/video.md +515 -22
  16. package/docs/sos_management/security.md +4 -2
  17. package/docs/sos_management/wifi.md +9 -9
  18. package/es6/FrontApplet/Browser/Browser.d.ts +25 -9
  19. package/es6/FrontApplet/Browser/Browser.js +25 -9
  20. package/es6/FrontApplet/Browser/Browser.js.map +1 -1
  21. package/es6/FrontApplet/Browser/IOpenLinkOptions.d.ts +7 -0
  22. package/es6/FrontApplet/Browser/IOpenLinkOptions.js.map +1 -1
  23. package/es6/FrontApplet/Browser/events.d.ts +6 -0
  24. package/es6/FrontApplet/Browser/events.js.map +1 -1
  25. package/es6/FrontApplet/Command/Command.d.ts +15 -6
  26. package/es6/FrontApplet/Command/Command.js +15 -6
  27. package/es6/FrontApplet/Command/Command.js.map +1 -1
  28. package/es6/FrontApplet/Command/ICommand.d.ts +7 -0
  29. package/es6/FrontApplet/Command/ICommandEvent.d.ts +6 -0
  30. package/es6/FrontApplet/Debug/Debug.d.ts +11 -3
  31. package/es6/FrontApplet/Debug/Debug.js +11 -3
  32. package/es6/FrontApplet/Debug/Debug.js.map +1 -1
  33. package/es6/FrontApplet/DeviceInfo/DeviceInfo.d.ts +15 -0
  34. package/es6/FrontApplet/DeviceInfo/DeviceInfo.js +16 -2
  35. package/es6/FrontApplet/DeviceInfo/DeviceInfo.js.map +1 -1
  36. package/es6/FrontApplet/Display/Display.d.ts +22 -14
  37. package/es6/FrontApplet/Display/Display.js +22 -14
  38. package/es6/FrontApplet/Display/Display.js.map +1 -1
  39. package/es6/FrontApplet/Display/IDisplay.d.ts +4 -0
  40. package/es6/FrontApplet/FileSystem/FileSystem.d.ts +429 -41
  41. package/es6/FrontApplet/FileSystem/FileSystem.js +427 -39
  42. package/es6/FrontApplet/FileSystem/FileSystem.js.map +1 -1
  43. package/es6/FrontApplet/FileSystem/HashAlgorithm.d.ts +4 -1
  44. package/es6/FrontApplet/FileSystem/types.d.ts +46 -0
  45. package/es6/FrontApplet/FileSystem/types.js.map +1 -1
  46. package/es6/FrontApplet/FrontApplet.d.ts +31 -7
  47. package/es6/FrontApplet/FrontApplet.js +32 -8
  48. package/es6/FrontApplet/FrontApplet.js.map +1 -1
  49. package/es6/FrontApplet/Input/IKeyUpEvent.d.ts +9 -0
  50. package/es6/FrontApplet/Input/IKeyUpEvent.js +6 -0
  51. package/es6/FrontApplet/Input/IKeyUpEvent.js.map +1 -1
  52. package/es6/FrontApplet/Input/Input.d.ts +17 -1
  53. package/es6/FrontApplet/Input/Input.js +17 -1
  54. package/es6/FrontApplet/Input/Input.js.map +1 -1
  55. package/es6/FrontApplet/NativeCommands/MDC/Mdc.d.ts +32 -11
  56. package/es6/FrontApplet/NativeCommands/MDC/Mdc.js +14 -11
  57. package/es6/FrontApplet/NativeCommands/MDC/Mdc.js.map +1 -1
  58. package/es6/FrontApplet/Stream/IStreamTrackInfo.d.ts +34 -0
  59. package/es6/FrontApplet/Stream/Stream.d.ts +245 -20
  60. package/es6/FrontApplet/Stream/Stream.js +245 -20
  61. package/es6/FrontApplet/Stream/Stream.js.map +1 -1
  62. package/es6/FrontApplet/Stream/StreamProtocol.d.ts +4 -0
  63. package/es6/FrontApplet/Stream/StreamProtocol.js +4 -0
  64. package/es6/FrontApplet/Stream/StreamProtocol.js.map +1 -1
  65. package/es6/FrontApplet/Stream/streamEventProperties.d.ts +11 -1
  66. package/es6/FrontApplet/Stream/streamEvents.d.ts +26 -0
  67. package/es6/FrontApplet/Video/IOptions.d.ts +41 -0
  68. package/es6/FrontApplet/Video/IVideoEvent.d.ts +8 -0
  69. package/es6/FrontApplet/Video/IVideoEvent.js.map +1 -1
  70. package/es6/FrontApplet/Video/IVideoProperties.d.ts +3 -0
  71. package/es6/FrontApplet/Video/Video.d.ts +256 -19
  72. package/es6/FrontApplet/Video/Video.js +258 -22
  73. package/es6/FrontApplet/Video/Video.js.map +1 -1
  74. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import IPostMessage from '../IPostMessage';
2
- import { IStorageUnit, IFilePath, IFile, IHeaders, ICopyFileOptions, IMoveFileOptions } from './types';
2
+ import { IStorageUnit, IFilePath, IFile, IHeaders, ICopyFileOptions, IMoveFileOptions, ExtractMethodType } from './types';
3
3
  import StorageUnitsChangedMessage from './StorageUnitsChangedMessage';
4
4
  import IFileSystem from './IFileSystem';
5
5
  import { HashAlgorithm } from './HashAlgorithm';
@@ -7,15 +7,35 @@ import { HashAlgorithm } from './HashAlgorithm';
7
7
  * The `sos.fileSystem` API groups together methods for low-level access to the file system. The File System API supports both internal and
8
8
  * external storage.
9
9
  *
10
- * :::warning
11
- *
10
+ * :::warning Differences between File System API and Offline Cache API
12
11
  * File System directory structure is **PERSISTENT** and is **NOT** automatically deleted through `Applet Reload` power action!
13
12
  * Applet Reload only deletes `/data` directory which is reserved for simplified [Offline Cache API](./offline). Use
14
13
  * `deleteFile()` to clear the device storage file system.
14
+ * :::
15
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)
16
18
  * :::
17
19
  *
18
- * @tutorial https://developers.signageos.io/docs/applets/api-guides/offline-content#storing-files-permanently
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
+ * @example
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
+ * });
19
39
  */
20
40
  export default class FileSystem implements IFileSystem {
21
41
  private messagePrefix;
@@ -27,14 +47,52 @@ export default class FileSystem implements IFileSystem {
27
47
  /**
28
48
  * The `listStorageUnits()` method lists all available storage units. All devices always have one internal storage device (with
29
49
  * `removable: false`) and zero or more external devices. The capacity values are in bytes.
50
+ *
51
+ * :::note
52
+ * 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).
53
+ * :::
54
+ *
55
+ * :::warning
56
+ * `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.
57
+ * :::
58
+ *
59
+ * @returns {Promise<IStorageUnit[]>} An array of storage units available on the device.
60
+ * @throws InternalFileSystemError Unexpected error occurred when listing storage units.
61
+ * @since 2.1.0
62
+ *
63
+ * @example
64
+ * // Storage units are equivalent to disk volumes (C:, D: etc on Windows; /mnt/disc1, /mnt/disc2 on Unix)
65
+ * const storageUnits = await sos.fileSystem.listStorageUnits();
66
+ * const externalStorageUnits = storageUnits.filter((storageUnit) => storageUnit.removable);
67
+ * externalStorageUnits.forEach((storageUnit) => {
68
+ * console.log(`Storage Unit Type: ${storageUnit.type}`);
69
+ * console.log(`Capacity: ${storageUnit.capacity} bytes`);
70
+ * });
30
71
  */
31
72
  listStorageUnits(): Promise<IStorageUnit[]>;
32
73
  /**
33
74
  * A shorthand method for listing only the internal storage units (i.e. those with the `removable: false`). The capacity values are in bytes.
75
+ *
76
+ * @returns {Promise<IStorageUnit[]>} An array of internal storage units available on the device.
77
+ * @since 7.0.0
78
+ *
79
+ * @example
80
+ * // List internal storage units
81
+ * const internalStorageUnits = await sos.fileSystem.listInternalStorageUnits();
82
+ * internalStorageUnits.forEach((storageUnit) => {
83
+ * console.log(`Storage Unit Type: ${storageUnit.type}`);
84
+ * console.log(`Capacity: ${storageUnit.capacity} bytes`);
85
+ * console.log(`Free Space: ${storageUnit.freeSpace} bytes`);
86
+ * console.log(`Usable Space: ${storageUnit.usableSpace} bytes`);
87
+ * });
34
88
  */
35
89
  listInternalStorageUnits(): Promise<IStorageUnit[]>;
36
90
  /**
37
91
  * The `onStorageUnitsChanged()` method sets up a listener, which is called whenever the list of storage units changes.
92
+ *
93
+ * @param listener The listener function to be called when the storage units change.
94
+ * @throws Error If `listener` is not a valid function.
95
+ * @since 2.1.0
38
96
  */
39
97
  onStorageUnitsChanged(listener: () => void): void;
40
98
  /**
@@ -42,78 +100,243 @@ export default class FileSystem implements IFileSystem {
42
100
  */
43
101
  removeStorageUnitsChangedListener(listener: () => void): void;
44
102
  /**
45
- * The `removeAllListeners()` method removes all listeners, previously added by `removeAllListeners()`
103
+ * The `removeAllListeners()` method removes all listeners, previously added by `onStorageUnitsChanged()`
46
104
  */
47
105
  removeAllListeners(): void;
48
106
  /**
49
107
  * The `listFiles()` method lists all files and directories in the specified path (nested files are not included).
50
108
  *
51
- * @throws If the path does not exist or it is a file.
109
+ * @param directoryPath The path to the directory where files will be listed.
110
+ * @returns {Promise<IFilePath[]>} A promise that resolves to an array of file paths in the specified directory.
111
+ * @throws Error If `directoryPath` is not a valid object or does not contain `storageUnit` and `filePath`.
112
+ * @throws Error If the path does not exist, or it is a file.
113
+ * @since 2.1.0
114
+ *
115
+ * @example
116
+ * // List files in the root directory of the internal storage unit
117
+ * const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
118
+ * const directoryPath = {
119
+ * storageUnit: internalStorageUnit,
120
+ * filePath: '', // Empty string is used as an absolute path instead of "/"
121
+ * };
122
+ *
123
+ * const files = await sos.fileSystem.listFiles(directoryPath);
124
+ * console.log('Files in the root directory:', files.length);
125
+ * files.forEach((file) => {
126
+ * console.log(`File: ${file.filePath}`);
127
+ * });
52
128
  */
53
129
  listFiles(directoryPath: IFilePath): Promise<IFilePath[]>;
54
130
  /**
55
131
  * The `exists()` method checks whether a file or directory exists.
132
+ *
133
+ * @param filePath The path to the file or directory to check.
134
+ * @returns {Promise<boolean>} A promise that resolves to `true` if the file or directory exists, `false` otherwise.
135
+ * @throws Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
136
+ * @throws Error If any error occurs during the existence check operation on the device.
137
+ * @since 2.1.0
138
+ *
139
+ * @example
140
+ * const filePath = {
141
+ * storageUnit: internalStorageUnit,
142
+ * filePath: 'path/to/file.txt',
143
+ * };
144
+ *
145
+ * const fileExists = await sos.fileSystem.exists(filePath);
146
+ * console.log(`File exists: ${fileExists}`); // Prints true if the file exists, false otherwise
56
147
  */
57
148
  exists(filePath: IFilePath): Promise<boolean>;
58
149
  /**
59
150
  * The `getFile()` method returns runtime information about a file path, such as local url, last modified date or size.
151
+ *
152
+ * :::warning
153
+ * 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.
154
+ * :::
155
+ *
156
+ * @param filePath The path to the file to be retrieved.
157
+ * @returns {Promise<IFile | null>} A promise that resolves to the file information or `null` if the file does not exist.
158
+ * @throws Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
159
+ * @throws Error If the file is a directory.
160
+ * @throws Error If any error occurs during the retrieval operation on the device.
161
+ * @since 2.1.0
162
+ *
163
+ * @example
164
+ * // Get file information
165
+ * const filePath = {
166
+ * storageUnit: internalStorageUnit,
167
+ * filePath: 'path/to/file.txt',
168
+ * };
169
+ *
170
+ * const fileInfo = await sos.fileSystem.getFile(filePath);
171
+ * console.log(JSON.stringify(fileInfo)); // Prints the file information
172
+ * console.log(fileInfo.localUri); // Prints the local URI of the file
60
173
  */
61
174
  getFile(filePath: IFilePath): Promise<IFile | null>;
62
175
  /**
63
- * The `writeFile()` method writes string content to the file specified by `filePath`. If the file does exist, it is created. If the directory
64
- * does not exist, an error is thrown.
176
+ * The `writeFile()` method writes string content to the file specified by `filePath`. If the file does exist, it is created.
177
+ *
178
+ * @param filePath The path to the file to be written.
179
+ * @param contents The content to be written to the file.
180
+ * @returns {Promise<void>} A promise that resolves when the content is written successfully.
181
+ * @throws Error If the parent directory does not exist or the `filePath` is a directory.
182
+ * @throws Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
183
+ * @throws Error If any error occurs during the write operation on the device.
184
+ * @since 3.2.0
65
185
  *
66
- * @throws If the parent directory does not exist or the `filePath` is a directory.
186
+ * @example
187
+ * const filePath = {
188
+ * storageUnit: internalStorageUnit,
189
+ * filePath: 'path/to/file.txt',
190
+ * };
191
+ *
192
+ * const contents = 'This is the content to write to the file.';
193
+ * await sos.fileSystem.writeFile(filePath, contents);
67
194
  */
68
195
  writeFile(filePath: IFilePath, contents: string): Promise<void>;
69
196
  /**
70
- * The `writeFile()` method appends string content to the file specified by `filePath`. If the file does exist, it is created. If the directory
71
- * does not exist, an error is thrown.
197
+ * The `appendFile()` method appends string content to the file specified by `filePath`.
198
+ * If the file does exist, it is created.
199
+ *
200
+ * :::note
201
+ * Only string can be appended to the file. If you want to append binary data, you have to convert it to a string first.
202
+ * :::
203
+ *
204
+ * @param filePath The path to the file to be appended.
205
+ * @param contents The content to be appended to the file.
206
+ * @returns {Promise<void>} A promise that resolves when the content is appended successfully.
207
+ * @throws Error If the parent directory does not exist.
208
+ * @throws Error If the `filePath` is a directory.
209
+ * @throws Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
210
+ * @throws Error If any error occurs during the append operation on the device.
211
+ * @since
212
+ *
213
+ * @example
214
+ * const filePath = {
215
+ * storageUnit: internalStorageUnit,
216
+ * filePath: 'path/to/file.txt',
217
+ * };
72
218
  *
73
- * @throws If the parent directory does not exist or the `filePath` is a directory.
219
+ * const contents = 'This is the content to append to the file.';
220
+ * await sos.fileSystem.appendFile(filePath, contents);
74
221
  */
75
222
  appendFile(filePath: IFilePath, contents: string): Promise<void>;
76
223
  /**
77
- * The `readFile()` method returns content of the file specified by `filePath`. The file has to be a text file, otherwise the content will be
78
- * mangled.
224
+ * The `readFile()` method returns content of the file specified by `filePath`.
225
+ * The file has to be a text file, otherwise the content will be mangled.
79
226
  *
80
- * @throws If the file does not exist.
227
+ * @param filePath The path to the file to be read.
228
+ * @returns {Promise<string>} A promise that resolves to the content of the file.
229
+ * @throws Error If the file does not exist.
230
+ * @throws Error If the `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
231
+ * @throws Error If the file is a directory.
232
+ * @throws Error If any error occurs during the read operation on the device.
233
+ * @since 3.3.0
234
+ *
235
+ * @example
236
+ * const filePath = {
237
+ * storageUnit: internalStorageUnit,
238
+ * filePath: 'path/to/file.txt',
239
+ * };
240
+ *
241
+ * const fileContent = await sos.fileSystem.readFile(filePath);
242
+ * console.log(`Content of the file: ${fileContent}`);
81
243
  */
82
244
  readFile(filePath: IFilePath): Promise<string>;
83
245
  /**
84
- * The `copyFile()` method creates a copy of file at `sourceFilePath` to `destinationFilePath`.
246
+ * The `copyFile()` method creates a copy of file from `sourceFilePath` to `destinationFilePath`.
247
+ *
248
+ * @param sourceFilePath The path to the file to be copied.
249
+ * @param destinationFilePath The path where the file will be copied to.
250
+ * @param options Options for copying the file.
251
+ * @param options.overwrite If set to `true`, the method will overwrite the destination file if it already exists.
252
+ * @returns {Promise<void>} A promise that resolves when the file is copied successfully.
253
+ * @throws Error If the source file does not exist.
254
+ * @throws Error If parent of the destination file path does not exist.
255
+ * @throws Error If `options` object is not valid.
256
+ * @throws Error If any error occurs during the copy operation on the device.
257
+ * @since 2.1.0
258
+ *
259
+ * @example
260
+ * // Copy file from one directory to another and overwrite it if it already exists
261
+ * const sourceFilePath = {
262
+ * storageUnit: internalStorageUnit,
263
+ * filePath: 'path/to/source/file.txt',
264
+ * };
85
265
  *
86
- * @param options.overwrite If not set or set to `false`, an error will be thrown if `destinationFilePath` already exists.
266
+ * const destinationFilePath = {
267
+ * storageUnit: internalStorageUnit,
268
+ * filePath: 'path/to/destination/file.txt',
269
+ * };
87
270
  *
88
- * @throws If the source file does not exists or parent of the destination file path does not exists. It also throws if the
89
- * `options.overwrite` is not set and the destination file path already exists.
271
+ * await sos.fileSystem.copyFile(sourceFilePath, destinationFilePath, { overwrite: true });
90
272
  */
91
273
  copyFile(sourceFilePath: IFilePath, destinationFilePath: IFilePath, options?: ICopyFileOptions): Promise<void>;
92
274
  /**
93
275
  * The `moveFile()` method moves a file from `sourceFilePath` to `destinationFilePath`.
94
276
  *
95
- * @throws If the source file does not exists or parent of the destination file path does not exists. It also throws if the
96
- * `options.overwrite` is not set and the destination file path already exists.
277
+ * @param sourceFilePath The path to the file to be moved.
278
+ * @param destinationFilePath The path where the file will be moved to.
279
+ * @param options Options for moving the file.
280
+ * @param options.overwrite If set to `true`, the method will overwrite the destination file if it already exists.
281
+ * @returns {Promise<void>} A promise that resolves when the file is moved successfully.
282
+ * @throws Error If the source file does not exist or parent of the destination file path does not exist.
283
+ * @throws Error If the `options.overwrite` is not set and the destination file path already exists.
284
+ * @throws Error If deleting path does not exist.
285
+ * @throws Error If any error occurs during the move operation on the device.
286
+ * @since 2.1.0
287
+ *
288
+ * @example
289
+ * // Move file from one directory to another and overwrite it if it already exists
290
+ * const sourceFilePath = {
291
+ * storageUnit: internalStorageUnit,
292
+ * filePath: 'path/to/source/file.txt',
293
+ * };
294
+ *
295
+ * const destinationFilePath = {
296
+ * storageUnit: internalStorageUnit,
297
+ * filePath: 'path/to/destination/file.txt',
298
+ * };
299
+ *
300
+ * await sos.fileSystem.moveFile(sourceFilePath, destinationFilePath, { overwrite: true });
97
301
  */
98
302
  moveFile(sourceFilePath: IFilePath, destinationFilePath: IFilePath, options?: IMoveFileOptions): Promise<void>;
99
303
  /**
100
- * The `deleteFile()` method deletes the file specified by `filePath`. To remove a directory set `recursive` to `true`.
304
+ * The `deleteFile()` method deletes the file specified by `filePath`.
305
+ *
306
+ * @param filePath The path to the file or directory to be deleted.
307
+ * @param recursive If set to `true`, the method will delete the directory and all its contents recursively.
308
+ * @returns {Promise<void>} A promise that resolves when the file is deleted successfully.
309
+ * @throws Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
310
+ * @throws Error If the file does not exist or if `recursive` is set to false and the file path is a directory.
311
+ * @throws Error If deleting path does not exist.
312
+ * @throws Error When is deleting directory and is not empty (not recursive).
313
+ * @since 2.1.0
314
+ *
315
+ * @example
316
+ * // Delete directory and all files inside
317
+ * //// First check, if there is such a directory
318
+ * if (await sos.fileSystem.exists({ storageUnit: internalStorageUnit, filePath: 'test-dir' })) {
319
+ * // Delete the directory and all it's content recursively
320
+ * await sos.fileSystem.deleteFile({ storageUnit: internalStorageUnit, filePath: 'test-dir' }, true);
321
+ * }
101
322
  *
102
- * @throws If the file does not exists or if `recursive` is set to false and the file path is a directory.
323
+ * // Delete file
324
+ * //// First check, if there is such a file
325
+ * if (await sos.fileSystem.exists({ storageUnit: internalStorageUnit, filePath: 'test-dir/downloaded-file.png' })) {
326
+ * // Delete the file
327
+ * await sos.fileSystem.deleteFile({ storageUnit: internalStorageUnit, filePath: 'test-dir/downloaded-file.png' }, false);
328
+ * }
103
329
  */
104
330
  deleteFile(filePath: IFilePath, recursive: boolean): Promise<void>;
105
331
  /**
106
- * The `downloadFile()` method download a file from `sourceUri` and saves it to the specified path. If the file already exists it is
107
- * overwritten. Optionally, headers for the download request may be specified. A HEAD request is always sent first to get `content-length`
108
- * of the downloaded file.
332
+ * The `downloadFile()` method download a file from `sourceUri` and saves it to the specified path. If the file already exists, the file will be
333
+ * overwritten. Optionally, headers for the download request may be specified.
109
334
  *
110
- * :::warning
111
- * - For every download request, our app makes HEAD request for `content-length` header on that downloaded file.
112
- * - Windows platform can download only files smaller then 4GB.
335
+ * :::danger
336
+ * 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.
113
337
  * :::
114
338
  *
115
339
  * #### Encoding
116
- *
117
340
  * 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).
118
341
  *
119
342
  * Download file method is always sending optional following headers:
@@ -143,50 +366,215 @@ export default class FileSystem implements IFileSystem {
143
366
  * - Raspberry Pi
144
367
  * - Windows
145
368
  *
146
- * @throws If the network request fails, parent directory does not exist, or the file path is a directory.
369
+ * @param filePath The path where the downloaded file will be saved.
370
+ * @param sourceUri The URI of the file to be downloaded.
371
+ * @param headers 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
372
+ * @returns {Promise<void>} A promise that resolves when the file is downloaded successfully.
373
+ * @throws Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
374
+ * @throws Error If `sourceUri` is not a valid URI.
375
+ * @throws Error If `headers` is not a valid object.
376
+ * @throws Error If the parent directory of `filePath` does not exist.
377
+ * @throws Error If the network request fails.
378
+ * @since 2.1.0
379
+ *
380
+ * @example
381
+ * const filePath = {
382
+ * storageUnit: internalStorageUnit,
383
+ * filePath: 'path/to/downloaded/file.zip',
384
+ * };
385
+ * const sourceUri = 'https://example.com/path/to/file.zip';
386
+ * const headers = {
387
+ * 'Authorization': 'Bearer your_token_here',
388
+ * };
389
+ * await sos.fileSystem.downloadFile(filePath, sourceUri, headers);
147
390
  */
148
391
  downloadFile(filePath: IFilePath, sourceUri: string, headers?: IHeaders): Promise<void>;
149
392
  /**
150
- * The `decompressFile()` method decompresses the file at `archiveFilePath` into a new file specified by `destinationDirectoryPath`.
393
+ * The `extractFile()` method extract (recursively) the archive file at `archiveFilePath` into a new file specified by `destinationDirectoryPath`.
151
394
  *
152
- * @throws If the archive file path does not exist, it is not a valid archive file or the destination directory does not exist.
395
+ * :::note
396
+ * - The directory/folder you are extracting your ZIP file into has to be created BEFORE you start extracting the ZIP.
397
+ * - Only supported extract method is `zip`.
398
+ * :::
399
+ *
400
+ * @param archiveFilePath The path to the archive file to be decompressed.
401
+ * @param destinationDirectoryPath The path to the directory where the decompressed files will be saved.
402
+ * @param method Extract method to use for extracting, e.g. 'zip'.
403
+ * @throws Error If the archive file path does not exist.
404
+ * @throws Error If it is not a valid archive file.
405
+ * @throws Error If destination directory does not exist.
406
+ * @since 2.1.0
407
+ *
408
+ * @example
409
+ * const archiveFilePath = {
410
+ * storageUnit: internalStorageUnit,
411
+ * filePath: 'path/to/archive.zip',
412
+ * };
413
+ *
414
+ * const destinationDirectoryPath = {
415
+ * storageUnit: internalStorageUnit,
416
+ * filePath: 'path/to/destination/directory',
417
+ * };
418
+ *
419
+ * await sos.fileSystem.extractFile(archiveFilePath, destinationDirectoryPath, 'zip');
153
420
  */
154
- extractFile(archiveFilePath: IFilePath, destinationDirectoryPath: IFilePath, method: string): Promise<void>;
421
+ extractFile(archiveFilePath: IFilePath, destinationDirectoryPath: IFilePath, method: ExtractMethodType): Promise<void>;
155
422
  /**
156
- * The `createArchive()` method creates an arch file at `archiveFilePath` from `archiveEntries` files.
423
+ * The `createArchive()` method creates an archive file from selected files and directories.
157
424
  *
158
425
  * :::warning
426
+ * - Never start OR end the `filePath` with a slash - `/`.
427
+ * - It is a good practice to check if file exists - `exists()` prior creating it
428
+ * :::
159
429
  *
160
- * This function is available only on Tizen devices.
161
- *
430
+ * :::info
431
+ * - This function is available only on Tizen devices.
432
+ * - All files are added to the archive based on absolute path from root directory.
162
433
  * :::
434
+ *
435
+ * @param archiveFilePath The path where the archive file will be created.
436
+ * @param archiveEntries An array of file paths to be included in the archive.
437
+ * @returns {Promise<void>} A promise that resolves when the archive file is created successfully.
438
+ * @throws Error If `archiveFilePath` is not a valid object or does not contain `storageUnit` and `filePath`.
439
+ * @throws Error If `archiveEntries` is not a valid array of objects.
440
+ * @throws Error If the parent directory of `archiveFilePath` does not exist.
441
+ * @throws Error If any of the `archiveEntries` do not exist or are directories.
442
+ * @throws Error If creating the archive file fails.
443
+ * @throws Error If the platform does not support creating archive files.
444
+ * @since 5.12.0
445
+ *
446
+ * @example
447
+ * const archiveFilePath = {
448
+ * storageUnit: internalStorageUnit,
449
+ * filePath: 'path/to/archive.zip',
450
+ * };
451
+ *
452
+ * const archiveEntries = [
453
+ * {
454
+ * storageUnit: internalStorageUnit,
455
+ * filePath: 'path/to/file1.txt',
456
+ * },
457
+ * {
458
+ * storageUnit: internalStorageUnit,
459
+ * filePath: 'path/to/file2.txt',
460
+ * },
461
+ * {
462
+ * storageUnit: internalStorageUnit,
463
+ * filePath: 'path/to/directory1',
464
+ * },
465
+ * ];
466
+ *
467
+ * await sos.fileSystem.createArchive(archiveFilePath, archiveEntries);
163
468
  */
164
469
  createArchive(archiveFilePath: IFilePath, archiveEntries: IFilePath[]): Promise<void>;
165
470
  /**
166
471
  * The `getChecksumFile()` method computes a checksum of the file specified by `filePath`.
167
472
  *
168
- * @throws If the file does not exist or it is a directory.
473
+ * :::warning Tizen limitation
474
+ * 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.
475
+ * Reason: MD5 file checksum is not available on any Tizen displays due to the Samsung restriction.
476
+ * :::
477
+ *
478
+ * @param filePath The path to the file for which the checksum will be computed.
479
+ * @param hashType The type of hash algorithm to use for computing the checksum.
480
+ * @returns {Promise<string>} A promise that resolves to the computed checksum of the file.
481
+ * @throws Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
482
+ * @throws Error If `hashType` is not a valid type or string.
483
+ * @throws Error If the file does not exist.
484
+ * @throws Error If `filepath` it is a directory
485
+ *
486
+ * @example
487
+ * const filePath = {
488
+ * storageUnit: internalStorageUnit,
489
+ * filePath: 'path/to/file.txt',
490
+ * };
491
+ *
492
+ * const checksum = await sos.fileSystem.getFileChecksum(filePath, 'md5');
493
+ * console.log(`Checksum of the file: ${checksum}`);
169
494
  */
170
495
  getFileChecksum(filePath: IFilePath, hashType: HashAlgorithm): Promise<string>;
171
496
  /**
172
497
  * The `createDirectory()` method create a new directory at specified path.
173
498
  *
174
- * @throws If the directory already exists or its parent directory does not exist.
499
+ * :::warning
500
+ * - Never start OR end the filePath with a slash - `/`.
501
+ * - It is a good practice to check if directory exists - `isDirectory()` prior creating it.
502
+ * :::
503
+ *
504
+ * @param directoryPath The path where the new directory will be created.
505
+ * @returns {Promise<void>} A promise that resolves when the directory is created successfully.
506
+ * @throws Error If `directoryPath` is not a valid object or does not contain `storageUnit` and `filePath`.
507
+ * @throws Error If the directory already exists.
508
+ * @throws Error If parent directory does not exist.
509
+ * @since 2.1.0
510
+ *
511
+ * @example
512
+ * const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
513
+ * const directoryPath = {
514
+ * storageUnit: internalStorageUnit,
515
+ * filePath: 'path/to/new/directory',
516
+ * };
517
+ *
518
+ * await sos.fileSystem.createDirectory(directoryPath);
175
519
  */
176
520
  createDirectory(directoryPath: IFilePath): Promise<void>;
177
521
  /**
178
522
  * The `isDirectory()` method checks whether the file path points to a directory.
179
523
  *
180
- * @throws If the file path does not exist.
524
+ * @param filePath The file path to check.
525
+ * @returns {Promise<boolean>} A promise that resolves to `true` if the file path is a directory, `false` otherwise.
526
+ * @throws Error If `filePath` is not a valid object or does not contain `storageUnit` and `filePath`.
527
+ * @throws Error If the file path does not exist.
528
+ * @since 2.1.0
529
+ *
530
+ * @example
531
+ * const filePath = {
532
+ * storageUnit: internalStorageUnit,
533
+ * filePath: 'path/to/directory',
534
+ * };
535
+ * const isDir = await sos.fileSystem.isDirectory(filePath);
536
+ * if (isDir) {
537
+ * console.log('The file path is a directory.');
538
+ * } else {
539
+ * console.log('The file path is not a directory.');
540
+ * }
181
541
  */
182
542
  isDirectory(filePath: IFilePath): Promise<boolean>;
183
543
  /**
184
- * The `link()` method creates a symbolic link to `sourceFilePath` (existing path) from `destinationFilePath` (new path).
544
+ * The `link()` method creates a symbolic link from `sourceFilePath` (existing path) to `destinationFilePath` (new path).
545
+ *
546
+ * :::note
547
+ * This method is only available on Linux devices.
548
+ * :::
549
+ *
550
+ * @param sourceFilePath The path to the existing file or directory that you want to link to.
551
+ * @param destinationFilePath The path where the symbolic link will be created.
552
+ * @throws Error If `sourceFilePath` or `destinationPath` is not a valid object or does not contain `storageUnit` and `filePath`.
553
+ * @throws Error If the `sourceFilePath` does not exist or if the `destinationFilePath` already exists.
554
+ * @throws Error The platform does not support linking directories.
555
+ * @returns {Promise<void>} A promise that resolves when the symbolic link is created successfully.
556
+ * @since 4.0.0
557
+ *
558
+ * @example
559
+ * const internalStorageUnit = (await sos.fileSystem.listInternalStorageUnits())[0];
560
+ * const sourceFilePath = {
561
+ * storageUnit: internalStorageUnit,
562
+ * filePath: 'path/to/existing/file.txt',
563
+ * };
564
+ *
565
+ * const destinationFilePath = {
566
+ * storageUnit: internalStorageUnit,
567
+ * filePath: 'path/to/symlink/file_link.txt',
568
+ * };
569
+ *
570
+ * await sos.fileSystem.link(sourceFilePath, destinationFilePath);
185
571
  */
186
572
  link(sourceFilePath: IFilePath, destinationFilePath: IFilePath): Promise<void>;
187
573
  /**
188
574
  * The `wipeout()` method is used to wipe out all data from the file system, later when action is finished the device is rebooted.
189
575
  *
576
+ * @returns {Promise<void>} A promise that resolves when the wipeout is complete.
577
+ *
190
578
  * :::danger
191
579
  * - Ensure that function is called only once, otherwise it will wipe out the file system again on applet start!
192
580
  * - This function is clearing internal file system storage, cache storage and cookies. Local storage will not be cleared.