Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b059b1a
feat: add nvmrc file
Kefan1997 Apr 12, 2024
dab6f86
feat: add yarn lock file
Kefan1997 Apr 12, 2024
00a744d
feat: add gitignore
Kefan1997 Apr 12, 2024
3e9a566
feat: add helpers
Kefan1997 Apr 12, 2024
bf791e3
feat: add create implementation
Kefan1997 Apr 12, 2024
f716bc9
feat: rename helper function
Kefan1997 Apr 12, 2024
e3d523d
feat: implement copy function
Kefan1997 Apr 12, 2024
1b6dd9e
feat: implement rename function
Kefan1997 Apr 12, 2024
35a802c
feat: implement delete function
Kefan1997 Apr 15, 2024
aa41b01
feat: implement list function
Kefan1997 Apr 15, 2024
bd5bede
feat: implement read function
Kefan1997 Apr 15, 2024
482bcbb
feat: implement parseEnv function
Kefan1997 Apr 16, 2024
68d4439
feat: implement parseArgs function
Kefan1997 Apr 16, 2024
bb4dec5
feat: implement modules
Kefan1997 Apr 22, 2024
4514933
fix: fix file name when importing files
Kefan1997 Apr 23, 2024
ccbbca4
feat: implement read function by stream
Kefan1997 Jul 8, 2024
3b0879a
feat: implement write function by stream
Kefan1997 Jul 8, 2024
8415e65
feat: implement transform function by stream
Kefan1997 Jul 8, 2024
4b781c6
feat: implement compress function
Kefan1997 Jul 8, 2024
28a4c58
feat: implement decompress function
Kefan1997 Jul 8, 2024
9433ce2
fix: use the built-in module node:stream
Kefan1997 Jul 9, 2024
1ce66a7
feat: implement worker logic
Kefan1997 Jul 9, 2024
8273c69
feat: implement logic for worker threads main
Kefan1997 Jul 9, 2024
80dc01a
feat: add tests files
Kefan1997 Aug 8, 2024
deba991
fix: remove import
Kefan1997 Aug 8, 2024
d6ac9b9
feat: implement child process function
Kefan1997 Aug 8, 2024
419b5d6
feat: add new script
Kefan1997 Aug 8, 2024
0f90aa7
feat: update node.js version
Kefan1997 Oct 7, 2024
46cb880
feat: implement calculationHash function
Kefan1997 Oct 7, 2024
ab49b13
feat: delete test.js file
Kefan1997 Oct 7, 2024
d527633
feat: delete copyWithStream.js file
Kefan1997 Oct 7, 2024
ce10733
feat: delete command copyWithStream
Kefan1997 Oct 7, 2024
a83136d
feat: delete test files
Kefan1997 Oct 7, 2024
d948caa
feat: fix problem with esm.mjs file
Kefan1997 Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.vscode
node_modules
yarn-error.log
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.9.0
14 changes: 12 additions & 2 deletions src/cli/args.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const parseArgs = () => {
// Write your code here
const args = process.argv.slice(2);
const res = [];

for (let i = 0; i < args.length; i = i + 2) {
const propName = args[i].substring(2);
const value = args[i + 1];

res.push(`${propName} is ${value}`);
}

console.log(res.join(', '));
};

parseArgs();
parseArgs();
10 changes: 8 additions & 2 deletions src/cli/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const parseEnv = () => {
// Write your code here
const pref = 'RSS_';

for(const key in process.env) {
if(key.startsWith(pref)) {
console.log(`${key}=${process.env[key]}`)
}
}
};

parseEnv();
parseEnv();
19 changes: 17 additions & 2 deletions src/cp/cp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { spawn } from 'child_process';

import { getPath } from "../helpers/index.js";

const spawnChildProcess = async (args) => {
// Write your code here
const childPath = getPath(import.meta.url, 'files', 'script.js');

const child = spawn('node', [childPath, ...args], {
stdio: ['pipe', 'pipe', 'inherit']
})

process.stdin.pipe(child.stdin);
child.stdout.pipe(process.stdout);

child.on('close', (code) => {
console.log(`Child process exited with code ${code}`)
})
};

// Put your arguments in function call to test this functionality
spawnChildProcess( /* [someArgument1, someArgument2, ...] */);
spawnChildProcess(['arg1', 'arg2', 'arg3']);
41 changes: 40 additions & 1 deletion src/fs/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import { mkdir, readdir, copyFile } from 'node:fs/promises';
import { join } from 'node:path';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';

const copy = async () => {
// Write your code here
try {
const DESTINATION_FOLDER_NAME = 'files_copy';
const sourceFolderPath = getPath(import.meta.url, 'files');
const sourceFolderExist = await doesPathExist(sourceFolderPath);

if (!sourceFolderExist) {
operationFail();

return;
}

const destinationFolderPath = getPath(import.meta.url, DESTINATION_FOLDER_NAME);
const destinationFolderExist = await doesPathExist(destinationFolderPath);

if (destinationFolderExist) {
operationFail();

return;
}

await mkdir(destinationFolderPath);

const files = await readdir(sourceFolderPath);

await Promise.all(
files.map(async (file) => {
const sourceFilePath = join(sourceFolderPath, file);
const destinationFilePath = join(destinationFolderPath, file);

await copyFile(sourceFilePath, destinationFilePath);
})
);
} catch (err) {
throw err;
}
};

await copy();
25 changes: 23 additions & 2 deletions src/fs/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { writeFile } from 'node:fs';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';

const create = async () => {
// Write your code here
const content = 'I am fresh and young';
const path = getPath(import.meta.url, 'files', 'fresh.txt');

const fileExist = await doesPathExist(path);

if (fileExist) {
operationFail();

return;
}

await writeFile(path, content, (err) => {
if (err) {
throw err;
} else {
console.log('File written successfully');
}
});
};

await create();
await create();
17 changes: 15 additions & 2 deletions src/fs/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import fsPromises from 'node:fs/promises';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';

const remove = async () => {
// Write your code here
const pathFile = getPath(import.meta.url, 'files', 'fileToRemove.txt');
const isFileExist = await doesPathExist(pathFile);

if (!isFileExist) {
operationFail();

return;
}

await fsPromises.rm(pathFile);
};

await remove();
await remove();
29 changes: 27 additions & 2 deletions src/fs/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import fsPromises from 'node:fs/promises';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';
import { join } from 'node:path';

const list = async () => {
// Write your code here
const dirPath = getPath(import.meta.url, 'files');
const isDirExist = await doesPathExist(dirPath);

if (!isDirExist) {
operationFail();

return;
}

const files = await fsPromises.readdir(dirPath);
const fileNames = [];

for (const file of files) {
const fileInfo = await fsPromises.stat(join(dirPath, file));

if (fileInfo.isFile()) {
fileNames.push(file);
}
}

console.log('files', fileNames);
};

await list();
await list();
18 changes: 16 additions & 2 deletions src/fs/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { readFile } from 'node:fs/promises';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';

const read = async () => {
// Write your code here
const filePath = getPath(import.meta.url, 'files', 'fileToRead.txt');
const isExist = doesPathExist(filePath);

if (!isExist) {
operationFail();

return;
}

const content = await readFile(filePath, { encoding: 'utf8' });
console.log(content);
};

await read();
await read();
26 changes: 24 additions & 2 deletions src/fs/rename.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import fs from 'node:fs/promises';

import { getPath, doesPathExist, operationFail } from '../helpers/index.js';

const rename = async () => {
// Write your code here
try {
const NEW_FILE_NAME = 'properFilename.md';
const OLD_FILE_NAME = 'wrongFilename.txt';

const newFileNamePath = getPath(import.meta.url, 'files', NEW_FILE_NAME);
const newFileExist = await doesPathExist(newFileNamePath);
const oldFileNamePath = getPath(import.meta.url, 'files', OLD_FILE_NAME);
const oldFileExist = await doesPathExist(oldFileNamePath);

if (newFileExist || !oldFileExist) {
operationFail();

return;
}

await fs.rename(oldFileNamePath, newFileNamePath);
} catch (err) {
throw err;
}
};

await rename();
await rename();
29 changes: 27 additions & 2 deletions src/hash/calcHash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { createReadStream } from 'fs';
import { createHash } from 'crypto';

import { getPath } from '../helpers/index.js';

const calculateHash = async () => {
// Write your code here
const folderName = 'files';
const fileToCalculateHashFor = 'fileToCalculateHashFor.txt';
const sha256 = 'sha256';

const pathToTheFile = getPath(import.meta.url, folderName, fileToCalculateHashFor);

const hash = createHash(sha256);
const stream = createReadStream(pathToTheFile);

stream.on('data', (data) => {
hash.update(data);
});

stream.on('end', () => {
const sha256Hash = hash.digest('hex');
console.log(`SHA256 Hash for ${fileToCalculateHashFor}: ${sha256Hash}`);
});

stream.on('error', (error) => {
console.error(`Error reading file: ${error.message}`);
});
};

await calculateHash();
await calculateHash();
32 changes: 32 additions & 0 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { access } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

export const getPath = (currentPath, folderName, fileName = '') => {
try {
const currentFile = fileURLToPath(currentPath);
const currentDirName = dirname(currentFile);

return join(currentDirName, folderName, fileName);
} catch (err) {
throw err;
}
};

export const doesPathExist = async (path) => {
try {
await access(path);

return true;
} catch (err) {
if (err.code === 'ENOENT') {
return false;
} else {
throw err;
}
}
};

export const operationFail = () => {
throw new Error('FS operation failed');
};
40 changes: 0 additions & 40 deletions src/modules/cjsToEsm.cjs

This file was deleted.

Loading