fix(core): update

This commit is contained in:
2021-11-30 16:34:35 +01:00
parent 98fa607c43
commit 1e60ab375b
4 changed files with 19533 additions and 3187 deletions

View File

@ -136,6 +136,11 @@ export class Smartfile extends plugins.smartjson.Smartjson {
await memory.toFs(this.contentBuffer, filePathArg);
}
/**
* writes the file to a directory combined with the relative path portion
* @param dirPathArg
* @returns
*/
public async writeToDir(dirPathArg: string) {
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg);
const filePath = plugins.path.join(dirPathArg, this.path);
@ -146,7 +151,16 @@ export class Smartfile extends plugins.smartjson.Smartjson {
/**
* read file from disk
*/
public async read() {}
public async read() {
this.contentBuffer = await fs.toBuffer(this.path);
}
/**
* deletes the file from disk at its original location
*/
public async delete() {
await fs.remove(this.path);
}
// -----------------------------------------------
// vinyl compatibility

View File

@ -202,6 +202,10 @@ export const toStringSync = (filePath: string): string => {
return fileString;
};
export const toBuffer = async (filePath: string): Promise<Buffer> => {
return plugins.fsExtra.readFile(filePath);
};
export const toBufferSync = (filePath: string): Buffer => {
return plugins.fsExtra.readFileSync(filePath);
};