fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-03 01:25:37 +01:00
parent 07b88a078d
commit 3d2789857c
2 changed files with 28 additions and 1 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartfile',
version: '10.0.34',
version: '10.0.35',
description: 'offers smart ways to work with files in nodejs'
}

View File

@ -65,6 +65,33 @@ export class Smartfile extends plugins.smartjson.Smartjson {
return new Smartfile(plugins.smartjson.parse(foldedJsonArg));
}
/**
* creates a Smartfile from a ReadableStream
* @param stream a readable stream that provides file content
* @param filePath the file path to associate with the content
* @param baseArg the base path to use for the file
*/
public static async fromStream(
stream: plugins.stream.Readable,
filePath: string,
baseArg: string = process.cwd()
): Promise<Smartfile> {
return new Promise<Smartfile>((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
stream.on('error', (error) => reject(error));
stream.on('end', () => {
const contentBuffer = Buffer.concat(chunks);
const smartfile = new Smartfile({
contentBuffer: contentBuffer,
base: baseArg,
path: plugins.path.relative(baseArg, filePath),
});
resolve(smartfile);
});
});
}
// ========
// INSTANCE
// ========