@capacitor/core#FilesystemDirectory TypeScript Examples
The following examples show how to use
@capacitor/core#FilesystemDirectory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: file-system.service.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
getFileHash(fileName: string, dir = FilesystemDirectory.Data): Observable<any> {
return from(Filesystem.readFile({
path: fileName,
directory: dir,
}))
.pipe(
map(result => (util.encode_utf8(result.data))),
switchMap(ab => crypto.hash.sha256(ab)),
map((intArr: Uint8Array) => util.Uint8Array_to_hex(intArr)),
);
}
Example #2
Source File: file-system.service.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
getJsonData(filename: string, parse = true, dir = FilesystemDirectory.Data): Observable<any> {
const readFile$ = defer(() => from(Filesystem.readFile({
encoding: this.defaultEncoding,
path: filename,
directory: dir,
})));
return readFile$
.pipe(
catchError(() => of({ data: null })),
map(readResult => readResult.data),
filter(data => data != null),
defaultIfEmpty('{}'),
map(data => parse ? JSON.parse(data) : data),
);
}
Example #3
Source File: file-system.service.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
saveJsonData<T extends Data>(data: T, dir = FilesystemDirectory.Data): Observable<string> {
const filename = (data.timestamp) ? `${data.timestamp}.json` : `${Date.now()}.json`;
const writeFile$ = defer(() => from(Filesystem.writeFile({
encoding: this.defaultEncoding,
path: filename,
data: JSON.stringify(data),
directory: dir,
})));
return writeFile$.pipe(map(() => filename));
}
Example #4
Source File: file-system.service.ts From mylog14 with GNU General Public License v3.0 | 5 votes |
deleteJsonData(filename: string, dir = FilesystemDirectory.Data): Observable<any> {
return defer(() => from(Filesystem.deleteFile({
path: filename,
directory: dir,
})));
}