Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ee2c6d5
feat: implement create
SlavikusVOG Oct 26, 2025
868b321
feat: implement copy functionality
SlavikusVOG Oct 26, 2025
5ce79b8
feat: implement rename function
SlavikusVOG Oct 26, 2025
65f3060
feat: implement delete function
SlavikusVOG Oct 26, 2025
ab78a34
fix: fix create file function
SlavikusVOG Oct 26, 2025
bff38a6
chore: remove useless import
SlavikusVOG Oct 26, 2025
c779380
fix: fix rename function
SlavikusVOG Oct 26, 2025
71f1e8d
fix: fix remove function
SlavikusVOG Oct 26, 2025
789e0db
feat: implement list function
SlavikusVOG Oct 26, 2025
496775f
feat: implement read function
SlavikusVOG Oct 26, 2025
38a7de3
feat: implement env function
SlavikusVOG Oct 26, 2025
6d3a95d
feat: implement args function
SlavikusVOG Oct 27, 2025
9174936
feat: create ecmascript module
SlavikusVOG Oct 27, 2025
38eda54
feat: implement calcHash function
SlavikusVOG Oct 27, 2025
4a6df38
feat: implement stream:read function
SlavikusVOG Oct 27, 2025
6ccb7a1
feat: implement stream:write function
SlavikusVOG Oct 27, 2025
7b1e7ae
feat: implement stream:transform function
SlavikusVOG Oct 27, 2025
a891f21
feat: implement zlib:compress function
SlavikusVOG Oct 27, 2025
5df37b3
feat: implement zlib.decompress function
SlavikusVOG Oct 27, 2025
9f97421
feat: implement workers function
SlavikusVOG Oct 27, 2025
5054b05
feat: implement child process function
SlavikusVOG Oct 27, 2025
371c031
fix: fix file path for functions from fs folder
SlavikusVOG Oct 28, 2025
c78ea17
fix: fix fs:delete function
SlavikusVOG Oct 28, 2025
1e87eb2
fix: fix module task
SlavikusVOG Oct 28, 2025
1746023
chore: remove cjsToEsm
SlavikusVOG Oct 28, 2025
fddac90
fix: fix result output
SlavikusVOG Oct 28, 2025
e3e68bd
fix: fix decompressed file name
SlavikusVOG Oct 28, 2025
383c358
fix: fix result output
SlavikusVOG Oct 28, 2025
5432101
refactor: remove import
SlavikusVOG Oct 28, 2025
5781278
fix: use static import instead of dynamic import
SlavikusVOG Oct 28, 2025
673c7ae
fix: fix json import
SlavikusVOG Oct 28, 2025
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
12 changes: 12 additions & 0 deletions src/cli/args.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const parseArgs = () => {
// Write your code here
let valueNameFlag = false;
const result = [];
process.argv.reduce((previous, current) => {
if (previous) {
result.push(`${previous} is ${current}`);
return null
}
else if (current.startsWith("--")) {
return current.substr(2);
}
});
console.log(result.join(', '));
};

parseArgs();
8 changes: 8 additions & 0 deletions src/cli/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const parseEnv = () => {
// Write your code here
const envVariablesKeys = Object.keys(process.env);
const result = []
envVariablesKeys.forEach((k) => {
if (k.startsWith("RSS_")) {
result.push(`${k}=${process.env[k]}`);
}
});
console.log(result.join("; "))
};

parseEnv();
13 changes: 12 additions & 1 deletion src/cp/cp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { spawn } from "node:child_process";

const filePath = "./src/cp/files/script.js";

const spawnChildProcess = async (args) => {
// Write your code here
const child = spawn("node", [filePath, ...args], {
stdio: ['pipe', 'pipe'],
});

process.stdin.pipe(child.stdin);

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

// Put your arguments in function call to test this functionality
spawnChildProcess( /* [someArgument1, someArgument2, ...] */);
spawnChildProcess( [true, 2, 'test3'] );
23 changes: 23 additions & 0 deletions src/fs/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import fs from "node:fs/promises";

const folder = "./src/fs/files";

const copy = async () => {
// Write your code here
try {
await fs.access(folder);
await fs.access(`${folder}_copy`);
throw new Error("FS operation failed");
}
catch(error) {
if (error.syscall === "access") {
try {
await fs.access(folder);
fs.cp(folder, `${folder}_copy`, {recursive: true});
}
catch(error) {
throw new Error("FS operation failed");
}
}
else {
throw error;
}
}
};

await copy();
32 changes: 32 additions & 0 deletions src/fs/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
import fs from "node:fs/promises";
import path from "node:path";

const fresh = "./src/fs/files/fresh.txt";
const str = "I am fresh and young";

const create = async () => {
// Write your code here
try {
const stat = await fs.stat(fresh);
if (stat.isFile()) {
throw Error("FS operation failed");
}
else {
await fs.rmdir(fresh);
await fs.writeFile(fresh, str);
}
}
catch(error) {
if (error.syscall === "stat") {
try {
await fs.access(path.dirname(fresh));
}
catch(error) {
fs.mkdir(path.dirname(fresh));
}
finally{
await fs.writeFile(fresh, str);
}
}
else {
throw error;
}
}
};

await create();
22 changes: 22 additions & 0 deletions src/fs/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import fs from "node:fs/promises";

const errorMessage = "FS operation failed";
const fileName = "./src/fs/files/fileToRemove.txt";

const remove = async () => {
// Write your code here
try {
const fileStat = await fs.stat(fileName);
if (fileStat.isFile()) {
await fs.rm(fileName);
}
else {
throw new Error(errorMessage);
}
}
catch(error) {
if (error.syscall === "stat") {
throw new Error(errorMessage);
}
else {
throw error
}
}
};

await remove();
20 changes: 20 additions & 0 deletions src/fs/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import fs from "node:fs/promises";

const errorMessage = "FS operation failed";
const directory = "./src/fs/files";

const list = async () => {
// Write your code here
const directoryStat = await fs.stat(directory);
if (directoryStat.isDirectory()) {
const files = await fs.readdir(directory);
await Promise.all(
files.map(async (f) => {
const fStat = await fs.stat(`${directory}/${f}`);
if (fStat.isFile()) {
console.log(f);
}
})
);
}
else {
throw new Error (errorMessage);
}
};

await list();
18 changes: 18 additions & 0 deletions src/fs/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import fs from "node:fs/promises";

const errorMessage = "FS operation failed";
const filePath = "./src/fs/files/fileToRead.txt";

const read = async () => {
// Write your code here
try {
const fileStat = await fs.stat(filePath);
if (fileStat.isFile()) {
const fileContent = await fs.readFile(filePath);
console.log(fileContent.toString());
}
else {
throw new Error(errorMessage);
}
}
catch(error) {
throw new Error(errorMessage);
}
};

await read();
28 changes: 28 additions & 0 deletions src/fs/rename.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import fs from "node:fs/promises";

const errorMessage = "FS operation failed";
const fileName = "./src/fs/files/wrongFilename.txt";
const properFilename = "./src/fs/files/properFilename.md";

const rename = async () => {
// Write your code here
try {
const fileNameStat = await fs.stat(fileName);
if (fileNameStat.isDirectory()) {
throw new Error(errorMessage);
}
await fs.stat(properFilename);
throw new Error(errorMessage);
}
catch(error) {
if (error.syscall === "stat") {
try {
await fs.access(fileName);
}
catch(error) {
throw new Error(errorMessage);
}
await fs.rename(fileName, properFilename);
}
else {
throw error
}
}
};

await rename();
11 changes: 11 additions & 0 deletions src/hash/calcHash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import crypto from "node:crypto";
import fs from "node:fs";

const filePath = "./src/hash/files/fileToCalculateHashFor.txt";

const calculateHash = async () => {
// Write your code here
const hash = crypto.createHash("sha256");
const input = fs.createReadStream(filePath);
for await (const chunk of input) {
hash.update(chunk);
}
console.log(hash.digest('hex'));
};

await calculateHash();
34 changes: 0 additions & 34 deletions src/modules/cjsToEsm.cjs

This file was deleted.

36 changes: 36 additions & 0 deletions src/modules/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import path from 'node:path';
import { release, version } from 'node:os';
import { createServer as createServerHttp } from 'node:http';

import './files/c.cjs';

const random = Math.random();

const unknownObject = (random > 0.5 /* ? a : b; */
? await import ('./files/a.json', { with: { type: 'json' }})
: await import('./files/b.json', { with: { type: 'json' }})).default;

console.log(`Release ${release()}`);
console.log(`Version ${version()}`);
console.log(`Path segment separator is "${path.sep}"`);

console.log(`Path to current file is ${import.meta.filename}`);
console.log(`Path to current directory is ${import.meta.dirname}`);

const myServer = createServerHttp((_, res) => {
res.end('Request accepted');
});

const PORT = 3000;

console.log(unknownObject);

myServer.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
console.log('To terminate it, use Ctrl+C combination');
});

export default {
unknownObject,
myServer,
};
9 changes: 9 additions & 0 deletions src/streams/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import fs from "node:fs";

const filePath = "./src/streams/files/fileToRead.txt";

const read = async () => {
// Write your code here
const input = fs.createReadStream(filePath);
for await (const chunk of input) {
process.stdout.write(chunk);
}
process.stdout.write('\n');
};

await read();
10 changes: 10 additions & 0 deletions src/streams/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import stream from "node:stream";

const transform = async () => {
// Write your code here
const reverser = new stream.Transform({
transform(chunk, encoding, callback) {
callback(null, chunk.toString().split('').reverse().join(''));
}
});
process.stdin
.pipe(reverser)
.pipe(process.stdout);
};

await transform();
6 changes: 6 additions & 0 deletions src/streams/write.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import fs from "node:fs";

const fileToWrite = "./src/streams/files/fileToWrite.txt";

const write = async () => {
// Write your code here
const output = fs.createWriteStream(fileToWrite);
process.stdin.pipe(output);
};

await write();
26 changes: 26 additions & 0 deletions src/wt/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
import os from "os";
import {
Worker, MessageChannel, MessagePort, isMainThread, parentPort
} from 'node:worker_threads';

const performCalculations = async () => {
// Write your code here
const coresCount = os.cpus().length;
const values = [];
for (let i = 10; i < 10 + coresCount; i++) {
values.push(i);
}
const results = await Promise.all(values.map(async (v, index) => {
return new Promise((resolve) => {
const worker = new Worker("./src/wt/worker.js", {
workerData: {n: v},
});
worker.on("message", (r) => {
resolve({status: "resolved", data: r});
});
worker.on("error", (error) => {
resolve({status: "error", data: null});
})
})
}));
results.forEach((r) => {
console.log(`{status: ${r.status}, data: ${r.data}}`);
})
};

await performCalculations();
Loading