fs/promises#copyFile TypeScript Examples
The following examples show how to use
fs/promises#copyFile.
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: MigrationService.ts From context-mod with MIT License | 6 votes |
async backupDatabase() {
try {
if (this.database.options.type === 'sqljs' && this.database.options.location !== undefined) {
try {
const ts = Date.now();
const backupLocation = `${this.database.options.location}.${ts}.bak`
this.dbLogger.info(`Detected sqljs (sqlite) database. Will try to make a backup at ${backupLocation}`, {leaf: 'Backup'});
await copyFile(this.database.options.location, backupLocation, constants.COPYFILE_EXCL);
this.dbLogger.info('Successfully created backup!', {leaf: 'Backup'});
} catch (err: any) {
throw new ErrorWithCause('Cannot make an automated backup of your configured database.', {cause: err});
}
} else {
let msg = 'Cannot make an automated backup of your configured database.';
if (this.database.options.type !== 'sqljs') {
msg += ' Only SQlite (sqljs database type) is implemented for automated backups right now, sorry :( You will need to manually backup your database.';
} else {
// TODO don't throw for this??
msg += ' Database location is not defined (probably in-memory).';
}
throw new Error(msg);
}
} catch (e: any) {
this.dbLogger.error(e, {leaf: 'Backup'});
throw e;
}
}
Example #2
Source File: cache.ts From cloudmusic-vscode with MIT License | 6 votes |
static async put(
key: string,
name: string,
path: string,
md5?: string
): Promise<void> {
try {
if (!md5 || (await md5File(path)) === md5) {
const target = resolve(MUSIC_CACHE_DIR, name);
await copyFile(path, target);
const { size } = await stat(target);
this._deleteNode({ key, name });
this._addNode({ key, name, size });
}
} catch {}
}