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:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartfile',
|
||||
version: '13.0.0',
|
||||
version: '13.0.1',
|
||||
description: 'High-level file representation classes (SmartFile, StreamFile, VirtualDirectory) for efficient in-memory file management in Node.js using TypeScript. Works seamlessly with @push.rocks/smartfs for filesystem operations.'
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ export class SmartFile extends plugins.smartjson.Smartjson {
|
||||
);
|
||||
|
||||
// Rename the file on disk
|
||||
await plugins.fsExtra.rename(oldAbsolutePath, newAbsolutePath);
|
||||
await plugins.fsPromises.rename(oldAbsolutePath, newAbsolutePath);
|
||||
}
|
||||
|
||||
// Return the new path
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export class VirtualDirectory {
|
||||
const newVirtualDir = new VirtualDirectory(smartFs, factory);
|
||||
|
||||
// Use smartFs to list directory and factory to create SmartFiles
|
||||
const entries = await smartFs.directory(pathArg).list({ recursive: true });
|
||||
const entries = await smartFs.directory(pathArg).recursive().list();
|
||||
const smartfiles = await Promise.all(
|
||||
entries
|
||||
.filter((entry: any) => entry.isFile)
|
||||
|
||||
@@ -32,8 +32,7 @@ export {
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import fsExtra from 'fs-extra';
|
||||
import * as glob from 'glob';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export { fsExtra, glob, yaml };
|
||||
export { glob, yaml };
|
||||
|
||||
Reference in New Issue
Block a user