fix(fs): Improve fs and stream handling, enhance SmartFile/StreamFile, update tests and CI configs
This commit is contained in:
14
ts/memory.ts
14
ts/memory.ts
@@ -27,7 +27,7 @@ export interface IToFsOptions {
|
||||
export let toFs = async (
|
||||
fileContentArg: string | Buffer | SmartFile | StreamFile,
|
||||
filePathArg: string,
|
||||
optionsArg: IToFsOptions = {}
|
||||
optionsArg: IToFsOptions = {},
|
||||
) => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
@@ -57,7 +57,12 @@ export let toFs = async (
|
||||
throw new Error('fileContent is neither string nor Smartfile');
|
||||
}
|
||||
await smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
||||
plugins.fsExtra.writeFile(filePath, fileContent, { encoding: fileEncoding }, done.resolve);
|
||||
plugins.fsExtra.writeFile(
|
||||
filePath,
|
||||
fileContent,
|
||||
{ encoding: fileEncoding },
|
||||
done.resolve,
|
||||
);
|
||||
return await done.promise;
|
||||
};
|
||||
|
||||
@@ -84,7 +89,10 @@ export const toFsSync = (fileArg: string, filePathArg: string) => {
|
||||
plugins.fsExtra.writeFileSync(filePath, fileString, { encoding: 'utf8' });
|
||||
};
|
||||
|
||||
export let smartfileArrayToFs = async (smartfileArrayArg: SmartFile[], dirArg: string) => {
|
||||
export let smartfileArrayToFs = async (
|
||||
smartfileArrayArg: SmartFile[],
|
||||
dirArg: string,
|
||||
) => {
|
||||
await smartfileFs.ensureDir(dirArg);
|
||||
for (const smartfile of smartfileArrayArg) {
|
||||
await toFs(smartfile, dirArg, {
|
||||
|
Reference in New Issue
Block a user