• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export interface FileResponse {
17  /**
18   * File URI.
19   * @since 3
20   */
21  uri: string;
22
23  /**
24   * File size, in bytes.
25   * If type is dir, the length value is fixed to 0.
26   * @since 3
27   */
28  length: number;
29
30  /**
31   * Timestamp when the file is stored, which is the number of milliseconds elapsed since 1970/01/01 00:00:00.
32   * For lite wearables, the value is fixed to 0, because this parameter is restricted by the underlying file system.
33   * @since 3
34   */
35  lastModifiedTime: number;
36
37  /**
38   * File type. The values are as follows:
39   * dir: directory
40   * file: file
41   * @since 3
42   */
43  type: "dir" | "file";
44
45  /**
46   * File list. When the recursive value is true and the type is dir, the file information under the subdirectory will be returned.
47   * Otherwise, no value will be returned.
48   * @since 3
49   */
50  subFiles?: Array<FileResponse>;
51}
52
53/**
54 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
55 */
56export interface FileMoveOption {
57  /**
58   * URI of the file to move.
59   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
60   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
61   * 2. The maximum number of characters allowed is 128.
62   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
63   * @since 3
64   */
65  srcUri: string;
66
67  /**
68   * URI of the file moved to the target location.
69   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
70   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
71   * 2. The maximum number of characters allowed is 128.
72   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
73   * @since 3
74   */
75  dstUri: string;
76
77  /**
78   * Called when the source file is moved to the specified location successfully.
79   * This function returns the URI of the file moved to the target location.
80   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
81   * @since 3
82   */
83  success?: (uri: string) => void;
84
85  /**
86   * Called when moving fails.
87   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
88   * @since 3
89   */
90  fail?: (data: string, code: number) => void;
91
92  /**
93   * Called when the execution is completed.
94   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
95   * @since 3
96   */
97  complete?: () => void;
98}
99
100/**
101 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
102 */
103export interface FileListResponse {
104  /**
105   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
106   * @since 3
107   */
108  fileList: Array<FileResponse>;
109}
110
111/**
112 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
113 */
114export interface FileListOption {
115  /**
116   * URI of the directory.
117   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
118   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
119   * 2. The maximum number of characters allowed is 128.
120   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
121   * @since 3
122   */
123  uri: string;
124
125  /**
126   * Called when the list is obtained successfully.
127   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
128   * @since 3
129   */
130  success?: (data: FileListResponse) => void;
131
132  /**
133   * Called when the list fails to be obtained.
134   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
135   * @since 3
136   */
137  fail?: (data: string, code: number) => void;
138
139  /**
140   * Called when the execution is completed.
141   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
142   * @since 3
143   */
144  complete?: () => void;
145}
146
147export interface FileCopyOption {
148  /**
149   * URI of the file to copy.
150   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
151   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
152   * 2. The maximum number of characters allowed is 128.
153   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
154   * @since 3
155   */
156  srcUri: string;
157
158  /**
159   * URI of the file moved to the target location.
160   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
161   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
162   * 2. The maximum number of characters allowed is 128.
163   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
164   * @since 3
165   */
166  dstUri: string;
167
168  /**
169   * Called when the copy file is saved successful.
170   * This function returns the URI of the file saved to the target location.
171   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
172   * @since 3
173   */
174  success?: (uri: string) => void;
175
176  /**
177   * Called when the copy or save operation fails.
178   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
179   * @since 3
180   */
181  fail?: (data: string, code: number) => void;
182
183  /**
184   * Called when the execution is completed.
185   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
186   * @since 3
187   */
188  complete?: () => void;
189}
190
191export interface FileGetOption {
192  /**
193   * File URI, which cannot be an application resource path.
194   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
195   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
196   * 2. The maximum number of characters allowed is 128.
197   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
198   * @since 3
199   */
200  uri: string;
201
202  /**
203   * Whether to recursively obtain the file list under a subdirectory.
204   * The default value is false.
205   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
206   * @since 3
207   */
208  recursive?: boolean;
209
210  /**
211   * Called when file information is obtained successfully.
212   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
213   * @since 3
214   */
215  success?: (file: FileResponse) => void;
216
217  /**
218   * Called when file information fails to be obtained.
219   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
220   * @since 3
221   */
222  fail?: (data: string, code: number) => void;
223
224  /**
225   * Called when the execution is completed.
226   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
227   * @since 3
228   */
229  complete?: () => void;
230}
231
232export interface FileDeleteOption {
233  /**
234   * URI of the file to be deleted, which cannot be an application resource path.
235   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
236   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
237   * 2. The maximum number of characters allowed is 128.
238   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
239   * @since 3
240   */
241  uri: string;
242
243  /**
244   * Called when local files are deleted successfully.
245   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
246   * @since 3
247   */
248  success?: () => void;
249
250  /**
251   * Called when the deletion fails.
252   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
253   * @since 3
254   */
255  fail?: (data: string, code: number) => void;
256
257  /**
258   * Called when the execution is completed.
259   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
260   * @since 3
261   */
262  complete?: () => void;
263}
264
265/**
266 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
267 */
268export interface FileWriteTextOption {
269  /**
270   * URI of a local file. If it does not exist, a file will be created.
271   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
272   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
273   * 2. The maximum number of characters allowed is 128.
274   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
275   * @since 3
276   */
277  uri: string;
278
279  /**
280   * Character string to write into the local file.
281   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
282   * @since 3
283   */
284  text: string;
285
286  /**
287   * Encoding format. The default format is UTF-8.
288   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
289   * @since 3
290   */
291  encoding?: string;
292
293  /**
294   * Whether to enable the append mode. The default value is false.
295   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
296   * @since 3
297   */
298  append?: boolean;
299
300  /**
301   * Called when texts are written into a file successfully.
302   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
303   * @since 3
304   */
305  success?: () => void;
306
307  /**
308   * Called when texts fail to be written into a file.
309   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
310   * @since 3
311   */
312  fail?: (data: string, code: number) => void;
313
314  /**
315   * Called when the execution is completed.
316   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
317   * @since 3
318   */
319  complete?: () => void;
320}
321
322/**
323 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
324 */
325export interface FileReadTextResponse {
326  /**
327   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
328   * @since 3
329   */
330  text: string;
331}
332
333export interface FileReadTextOption {
334  /**
335   * URI of a local file.
336   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
337   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
338   * 2. The maximum number of characters allowed is 128.
339   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
340   * @since 3
341   */
342  uri: string;
343
344  /**
345   * Encoding format. The default format is UTF-8.
346   * Currently, only UTF-8 is supported.
347   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
348   * @since 3
349   */
350  encoding?: string;
351
352  /**
353   * Position where the reading starts.
354   * The default value is the start position of the file.
355   * @devices liteWearable, smartVision
356   * @since 3
357   */
358  position?: number;
359
360  /**
361   * Position where the reading starts.
362   * The default value is the start position of the file.
363   * @devices liteWearable, smartVision
364   * @since 3
365   */
366  length?: number;
367
368  /**
369   * Called when texts are read successfully.
370   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
371   * @since 3
372   */
373  success?: (data: FileReadTextResponse) => void;
374
375  /**
376   * Called when texts fail to be read.
377   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
378   * @since 3
379   */
380  fail?: (data: string, code: number) => void;
381
382  /**
383   * Called when the execution is completed.
384   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
385   * @since 3
386   */
387  complete?: () => void;
388}
389
390/**
391 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
392 */
393export interface FileWriteArrayBufferOption {
394  /**
395   * URI of a local file. If it does not exist, a file will be created.
396   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
397   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
398   * 2. The maximum number of characters allowed is 128.
399   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
400   * @since 3
401   */
402  uri: string;
403
404  /**
405   * Buffer from which the data is derived.
406   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
407   * @since 3
408   */
409  buffer: Uint8Array;
410
411  /**
412   * Offset to the position where the writing starts. The default value is 0.
413   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
414   * @since 3
415   */
416  position?: number;
417
418  /**
419   * Whether to enable the append mode.
420   * The default value is false. If the value is true, the position parameter will become invalid.
421   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
422   * @since 3
423   */
424  append?: boolean;
425
426  /**
427   * Called when data from a buffer is written into a file successfully.
428   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
429   * @since 3
430   */
431  success?: () => void;
432
433  /**
434   * Called when data from a buffer fails to be written into a file.
435   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
436   * @since 3
437   */
438  fail?: (data: string, code: number) => void;
439
440  /**
441   * Called when the execution is completed.
442   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
443   * @since 3
444   */
445  complete?: () => void;
446}
447
448/**
449 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
450 */
451export interface FileReadArrayBufferResponse {
452  /**
453   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
454   * @since 3
455   */
456  buffer: Uint8Array;
457}
458
459/**
460 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
461 */
462export interface FileReadArrayBufferOption {
463  /**
464   * URI of a local file.
465   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
466   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
467   * 2. The maximum number of characters allowed is 128.
468   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
469   * @since 3
470   */
471  uri: string;
472
473  /**
474   * Position where the reading starts.
475   * The default value is the start position of the file.
476   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
477   * @since 3
478   */
479  position?: number;
480
481  /**
482   * Length of the content to read.
483   * If this parameter is not set, all content of the file will be read.
484   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
485   * @since 3
486   */
487  length?: number;
488
489  /**
490   * Called when the buffer data is read successfully.
491   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
492   * @since 3
493   */
494  success?: (data: FileReadArrayBufferResponse) => void;
495
496  /**
497   * Called when the buffer data fails to be read.
498   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
499   * @since 3
500   */
501  fail?: (data: string, code: number) => void;
502
503  /**
504   * Called when the execution is completed.
505   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
506   * @since 3
507   */
508  complete?: () => void;
509}
510
511/**
512 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
513 */
514export interface FileAccessOption {
515  /**
516   * URI of the directory or file.
517   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
518   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
519   * 2. The maximum number of characters allowed is 128.
520   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
521   * @since 3
522   */
523  uri: string;
524
525  /**
526   * Called when the check result is obtained successfully.
527   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
528   * @since 3
529   */
530  success?: () => void;
531
532  /**
533   * Called when the check fails.
534   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
535   * @since 3
536   */
537  fail?: (data: string, code: number) => void;
538
539  /**
540   * Called when the execution is completed.
541   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
542   * @since 3
543   */
544  complete?: () => void;
545}
546
547/**
548 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
549 */
550export interface FileMkdirOption {
551  /**
552   * URI of the directory.
553   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
554   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
555   * 2. The maximum number of characters allowed is 128.
556   * 3. A maximum of five recursions are allowed for creating the directory.
557   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
558   * @since 3
559   */
560  uri: string;
561
562  /**
563   * Whether to create the directory after creating its upper-level directory recursively.
564   * The default value is false.
565   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
566   * @since 3
567   */
568  recursive?: boolean;
569
570  /**
571   * Called when the directory is created successfully.
572   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
573   * @since 3
574   */
575  success?: () => void;
576
577  /**
578   * Called when the creation fails.
579   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
580   * @since 3
581   */
582  fail?: (data: string, code: number) => void;
583
584  /**
585   * Called when the execution is completed.
586   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
587   * @since 3
588   */
589  complete?: () => void;
590}
591
592/**
593 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
594 */
595export interface FileRmdirOption {
596  /**
597   * URI of the directory.
598   * Restricted by the underlying file system of lite wearables, the value must meet the following requirements:
599   * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
600   * 2. The maximum number of characters allowed is 128.
601   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
602   * @since 3
603   */
604  uri: string;
605
606  /**
607   * Whether to delete files and subdirectories recursively.
608   * The default value is false.
609   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
610   * @since 3
611   */
612  recursive?: boolean;
613
614  /**
615   * Called when the directory is deleted successfully.
616   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
617   * @since 3
618   */
619  success?: () => void;
620
621  /**
622   * Called when the deletion fails.
623   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
624   * @since 3
625   */
626  fail?: (data: string, code: number) => void;
627
628  /**
629   * Called when the execution is completed.
630   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
631   * @since 3
632   */
633  complete?: () => void;
634}
635
636/**
637 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
638 */
639export default class File {
640  /**
641   * Moves the source file to a specified location.
642   * @param options Options.
643   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
644   */
645  static move(options: FileMoveOption): void;
646
647  /**
648   * Copies a source file and save the copy to a specified location.
649   * @param options Options.
650   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
651   */
652  static copy(options: FileCopyOption): void;
653
654  /**
655   * Obtains the list of files in a specified directory.
656   * @param options Options.
657   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
658   */
659  static list(options: FileListOption): void;
660
661  /**
662   * Obtains information about a local file.
663   * @param options Options.
664   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
665   */
666  static get(options: FileGetOption): void;
667
668  /**
669   * Deletes local files.
670   * @param options Options.
671   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
672   */
673  static delete(options: FileDeleteOption): void;
674
675  /**
676   * Writes texts into a file.
677   * @param options Options.
678   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
679   */
680  static writeText(options: FileWriteTextOption): void;
681
682  /**
683   * Reads texts from a file.
684   * @param options Options.
685   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
686   */
687  static readText(options: FileReadTextOption): void;
688
689  /**
690   * Writes data from a buffer into a file.
691   * @param options Options.
692   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
693   */
694  static writeArrayBuffer(options: FileWriteArrayBufferOption): void;
695
696  /**
697   * Reads buffer data from a file.
698   * @param options Options.
699   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
700   */
701  static readArrayBuffer(options: FileReadArrayBufferOption): void;
702
703  /**
704   * Checks whether a file or directory exists.
705   * @param options Options.
706   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
707   */
708  static access(options: FileAccessOption): void;
709
710  /**
711   * Creates a directory.
712   * @param options Options.
713   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
714   */
715  static mkdir(options: FileMkdirOption): void;
716
717  /**
718   * Deletes a directory.
719   * @param options Options.
720   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
721   */
722  static rmdir(options: FileRmdirOption): void;
723}
724