Compare commits

...

2 Commits

Author SHA1 Message Date
7b3194cc13 10.0.29 2023-08-23 09:38:49 +02:00
e1e821efec fix(core): update 2023-08-23 09:38:49 +02:00
4 changed files with 30 additions and 4 deletions

View File

@ -1,7 +1,7 @@
{
"name": "@push.rocks/smartfile",
"private": false,
"version": "10.0.28",
"version": "10.0.29",
"description": "offers smart ways to work with files in nodejs",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartfile',
version: '10.0.28',
version: '10.0.29',
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);
};
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
import * as fs from 'fs';
import * as path from 'path';
import * as stream from 'stream';
export { fs, path };
export { fs, path, stream };
// @pushrocks scope
import * as lik from '@push.rocks/lik';