diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 38bc66c..b231469 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartfile', - version: '10.0.33', + version: '10.0.34', description: 'offers smart ways to work with files in nodejs' } diff --git a/ts/smartfile.fs.ts b/ts/smartfile.fs.ts index 59a526c..f19981c 100644 --- a/ts/smartfile.fs.ts +++ b/ts/smartfile.fs.ts @@ -221,6 +221,18 @@ export const toBufferSync = (filePath: string): Buffer => { return plugins.fsExtra.readFileSync(filePath); }; +/** + * Creates a Readable Stream from a file path. + * @param filePath The path to the file. + * @returns {fs.ReadStream} + */ +export const toReadStream = (filePath: string): plugins.fs.ReadStream => { + if (!fileExistsSync(filePath)) { + throw new Error(`File does not exist at path: ${filePath}`); + } + return plugins.fsExtra.createReadStream(filePath); +}; + export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string) => { const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter); let combinedString = '';