fix(core): update
This commit is contained in:
parent
07b88a078d
commit
3d2789857c
@ -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'
|
||||
}
|
||||
|
@ -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
|
||||
// ========
|
||||
|
Loading…
Reference in New Issue
Block a user