2020-05-09 14:45:23 +00:00
|
|
|
/* typehints:start */
|
|
|
|
import { Application } from "../application";
|
|
|
|
/* typehints:end */
|
|
|
|
|
|
|
|
export const FILE_NOT_FOUND = "file_not_found";
|
|
|
|
|
|
|
|
export class StorageInterface {
|
|
|
|
constructor(app) {
|
|
|
|
/** @type {Application} */
|
|
|
|
this.app = app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the storage
|
|
|
|
* @returns {Promise<void>}
|
2022-02-14 08:59:10 +00:00
|
|
|
* @abstract
|
2020-05-09 14:45:23 +00:00
|
|
|
*/
|
|
|
|
initialize() {
|
|
|
|
abstract;
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a string to a file asynchronously
|
|
|
|
* @param {string} filename
|
|
|
|
* @param {string} contents
|
|
|
|
* @returns {Promise<void>}
|
2022-02-14 08:59:10 +00:00
|
|
|
* @abstract
|
2020-05-09 14:45:23 +00:00
|
|
|
*/
|
|
|
|
writeFileAsync(filename, contents) {
|
|
|
|
abstract;
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a string asynchronously. Returns Promise<FILE_NOT_FOUND> if file was not found.
|
|
|
|
* @param {string} filename
|
|
|
|
* @returns {Promise<string>}
|
2022-02-14 08:59:10 +00:00
|
|
|
* @abstract
|
2020-05-09 14:45:23 +00:00
|
|
|
*/
|
|
|
|
readFileAsync(filename) {
|
|
|
|
abstract;
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to delete a file
|
|
|
|
* @param {string} filename
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
deleteFileAsync(filename) {
|
|
|
|
// Default implementation does not allow deleting files
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
}
|