fix(core): update

This commit is contained in:
Philipp Kunz 2023-08-23 09:38:49 +02:00
parent 6b613d1b8a
commit e1e821efec
3 changed files with 29 additions and 3 deletions

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartfile', name: '@push.rocks/smartfile',
version: '10.0.28', version: '10.0.29',
description: 'offers smart ways to work with files in nodejs' description: 'offers smart ways to work with files in nodejs'
} }

View File

@ -11,4 +11,29 @@ export const createWriteStream = (pathArg: string) => {
return plugins.fs.createWriteStream(pathArg); return plugins.fs.createWriteStream(pathArg);
}; };
export const streamDirectory = async (dirPathArg: string) => {}; export const processFile = async (
filePath: string,
asyncFunc: (fileStream: plugins.stream.Readable) => Promise<void>
): Promise<void> => {
return new Promise((resolve, reject) => {
const fileStream = createReadStream(filePath);
asyncFunc(fileStream).then(resolve).catch(reject);
});
}
export const processDirectory = async (
directoryPath: string,
asyncFunc: (fileStream: plugins.stream.Readable) => Promise<void>
): Promise<void> => {
const files = plugins.fs.readdirSync(directoryPath, { withFileTypes: true });
for (const file of files) {
const fullPath = plugins.path.join(directoryPath, file.name);
if (file.isDirectory()) {
await processDirectory(fullPath, asyncFunc); // Recursively call processDirectory for directories
} else if (file.isFile()) {
await processFile(fullPath, asyncFunc); // Call async function with the file stream and wait for it
}
}
};

View File

@ -1,8 +1,9 @@
// node native scope // node native scope
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as stream from 'stream';
export { fs, path }; export { fs, path, stream };
// @pushrocks scope // @pushrocks scope
import * as lik from '@push.rocks/lik'; import * as lik from '@push.rocks/lik';