fix(smartfile): Stream and filesystem integrations: remove fs-extra, switch to fs/promises.rename, add Web WritableStream compatibility, and use smartFs recursive directory methods; update plugins exports and README.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import { Readable } from 'stream';
|
||||
import { Readable, Writable } from 'stream';
|
||||
|
||||
type TStreamSource = (streamFile: StreamFile) => Promise<Readable | ReadableStream>;
|
||||
|
||||
@@ -163,7 +163,13 @@ export class StreamFile {
|
||||
|
||||
this.checkMultiUse();
|
||||
const readStream = await this.createReadStream();
|
||||
const writeStream = await this.smartFs.file(filePathArg).writeStream();
|
||||
let writeStream = await this.smartFs.file(filePathArg).writeStream();
|
||||
|
||||
// Check if it's a Web WritableStream and convert to Node.js Writable
|
||||
if (writeStream && typeof (writeStream as any).getWriter === 'function') {
|
||||
// This is a Web WritableStream, convert it to Node.js Writable
|
||||
writeStream = Writable.fromWeb(writeStream as any);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
readStream.pipe(writeStream);
|
||||
@@ -181,7 +187,7 @@ export class StreamFile {
|
||||
this.checkMultiUse();
|
||||
const filePath = plugins.path.join(dirPathArg, this.relativeFilePath);
|
||||
const dirPath = plugins.path.parse(filePath).dir;
|
||||
await this.smartFs.directory(dirPath).create({ recursive: true });
|
||||
await this.smartFs.directory(dirPath).recursive().create();
|
||||
return this.writeToDisk(filePath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user