Add readstream

This commit is contained in:
Philipinho
2025-05-21 10:58:40 -07:00
parent 625bdc7024
commit f6e3230eec
4 changed files with 35 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import {
} from '../interfaces';
import { join } from 'path';
import * as fs from 'fs-extra';
import { Readable } from 'stream';
import { createReadStream } from 'node:fs';
export class LocalDriver implements StorageDriver {
private readonly config: LocalStorageConfig;
@ -43,6 +45,14 @@ export class LocalDriver implements StorageDriver {
}
}
async readStream(filePath: string): Promise<Readable> {
try {
return createReadStream(this._fullPath(filePath));
} catch (err) {
throw new Error(`Failed to read file: ${(err as Error).message}`);
}
}
async exists(filePath: string): Promise<boolean> {
try {
return await fs.pathExists(this._fullPath(filePath));