Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a6d30c2
feat: add file creating logic in create.js
IrakliAmbroladze Oct 25, 2025
7f56243
feat: add logic for checking file existence before writing
IrakliAmbroladze Oct 25, 2025
fd57966
Merge branch 'Create' into develop
IrakliAmbroladze Oct 25, 2025
a5c8d71
feat: implement folder coping
IrakliAmbroladze Oct 25, 2025
d4219ed
Merge branch 'Copy' into develop
IrakliAmbroladze Oct 25, 2025
3434776
feat: implement file rename functionality
IrakliAmbroladze Oct 25, 2025
ac5fe3b
Merge branch 'Rename' into develop
IrakliAmbroladze Oct 25, 2025
1f3e634
in process...
IrakliAmbroladze Oct 25, 2025
e0c66e1
fea: create file deletion function
IrakliAmbroladze Oct 25, 2025
074ca17
Merge branch 'Delete' into develop
IrakliAmbroladze Oct 25, 2025
30b4b9b
feat: create function for listing filenames in files directory
IrakliAmbroladze Oct 25, 2025
c15b859
Merge branch 'List' into develop
IrakliAmbroladze Oct 25, 2025
6aed636
feat: create file reader function
IrakliAmbroladze Oct 25, 2025
e870d03
Merge branch 'Read' into develop
IrakliAmbroladze Oct 25, 2025
611b5ef
fix: relative path for read.js
IrakliAmbroladze Oct 25, 2025
7af0b19
fix: relative path for rename.js
IrakliAmbroladze Oct 25, 2025
a13f246
fix: relative path for list.js
IrakliAmbroladze Oct 25, 2025
3130a95
fix: relative path for delete.js
IrakliAmbroladze Oct 25, 2025
be8d470
fix: relative path for create.js
IrakliAmbroladze Oct 25, 2025
a526346
fix: relative path for copy.js
IrakliAmbroladze Oct 25, 2025
6830790
Merge branch 'FixRelativePaths' into develop
IrakliAmbroladze Oct 25, 2025
538ffd5
feat: implement console of env variables starting on RSS_
IrakliAmbroladze Oct 25, 2025
e39071d
Merge branch 'CliEnv' into develop
IrakliAmbroladze Oct 25, 2025
fa0502c
feat: implement console of cli arguments via args.js
IrakliAmbroladze Oct 25, 2025
5e5e7b4
Merge branch 'Args' into develop
IrakliAmbroladze Oct 25, 2025
559cc77
refac: rewrite cjsToEsm.cjs into esm module
IrakliAmbroladze Oct 26, 2025
b32617d
Merge branch 'Modules' into develop
IrakliAmbroladze Oct 26, 2025
c36e7ff
feat: console SHA256 hash for a given file
IrakliAmbroladze Oct 26, 2025
dbf01ea
Merge branch 'Hash' into develop
IrakliAmbroladze Oct 26, 2025
b450e07
refac: use fileURLToPath in fs files for multiple OS compatabil
IrakliAmbroladze Oct 26, 2025
e935b53
Merge branch 'RefactorPaths' into develop
IrakliAmbroladze Oct 26, 2025
f3dcfba
feat: implement compressing a file
IrakliAmbroladze Oct 26, 2025
41321a3
feat: implement decompression of a file
IrakliAmbroladze Oct 26, 2025
0b933e3
Merge branch 'Zlib' into develop
IrakliAmbroladze Oct 26, 2025
40afeed
feat: create readbale stream
IrakliAmbroladze Oct 26, 2025
0cc1410
feat: create writable stream
IrakliAmbroladze Oct 26, 2025
1ccec0a
feat: implement transforming input in reversed order
IrakliAmbroladze Oct 26, 2025
d9fce17
Merge branch 'Streams' into develop
IrakliAmbroladze Oct 26, 2025
6cf32ac
feat(wt): pass fibonacci result to main thread
IrakliAmbroladze Oct 26, 2025
8835ef1
feat(wt): import cpu to get the number of cpus
IrakliAmbroladze Oct 26, 2025
e8c112e
feat: create worker threads based on cpu cores quantity
IrakliAmbroladze Oct 26, 2025
65034e7
Merge branch 'WorkerThreads' into develop
IrakliAmbroladze Oct 26, 2025
0a49c36
feat: spawn child process
IrakliAmbroladze Oct 26, 2025
33f5030
Merge branch 'ChildProcess' into develop
IrakliAmbroladze Oct 26, 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
8 changes: 8 additions & 0 deletions src/cli/args.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { argv } from "node:process";

const parseArgs = () => {
// Write your code here
const justArguments = argv.slice(2);
const result = [];
for (let i = 0; i < justArguments.length; i += 2) {
result.push(`${justArguments[i].slice(2)} is ${justArguments[i + 1]}`);
}
console.log(result.join(", "));
};

parseArgs();
9 changes: 9 additions & 0 deletions src/cli/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const parseEnv = () => {
// Write your code here
const envVariables = Object.entries(process.env);
const filteredVariables = envVariables.filter(([key]) =>
key.startsWith("RSS_"),
);
const stringifyFilteredVariables = filteredVariables.map(
([key, value]) => `${key}=${value}`,
);
const jointResult = stringifyFilteredVariables.join("; ");
console.log(jointResult);
};

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";
import { URL, fileURLToPath } from "node:url";
const spawnChildProcess = async (args) => {
// Write your code here
const scriptURL = new URL("./files/script.js", import.meta.url);
const scriptPath = fileURLToPath(scriptURL);
const child = spawn("node", [scriptPath, ...args], {
stdio: ["pipe", "pipe", "inherit"],
});

process.stdin.pipe(child.stdin);

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

// Put your arguments in function call to test this functionality
spawnChildProcess( /* [someArgument1, someArgument2, ...] */);
spawnChildProcess(["someArgument1", "someArgument2", "other argument"]);
24 changes: 24 additions & 0 deletions src/fs/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
import { cp } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";
const copy = async () => {
// Write your code here
const srcURL = new URL("./files/", import.meta.url);
const src = fileURLToPath(srcURL);
const destURL = new URL("./files_copy", import.meta.url);
const dest = fileURLToPath(destURL);
const errorMessage = "FS operation failed";
try {
try {
await cp(src, dest, {
errorOnExist: true,
recursive: true,
force: false,
});
} catch (e) {
throw new Error(errorMessage);
}
} catch (e) {
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
console.log(e);
}
}
};

await copy();
21 changes: 21 additions & 0 deletions src/fs/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { writeFile, access } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";

const create = async () => {
// Write your code here
const content = "I am fresh and young";
const fileURL = new URL("./files/fresh.txt", import.meta.url);
const file = fileURLToPath(fileURL);
const errorMessage = "FS operation failed";
try {
await access(file);
throw new Error(errorMessage);
} catch (e) {
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
try {
await writeFile(file, content);
} catch (e) {
console.log(e);
}
}
}
};

await create();
30 changes: 30 additions & 0 deletions src/fs/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
import { unlink, access } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";

const remove = async () => {
// Write your code here
const fileURL = new URL("./files/fileToRemove.txt", import.meta.url);
const filePath = fileURLToPath(fileURL);
const errorMessage = "FS operation failed";
try {
//check if file exists
try {
await access(filePath);
} catch (e) {
throw new Error(errorMessage);
}

//after ensuring in file existence try to delete it
//and handle if there is any error
try {
await unlink(filePath);
console.log("File deleted successfully");
} catch (e) {
console.log(e);
}
} catch (e) {
//handle both of custom thrown error and uknown one
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
console.log(e);
}
}
};

await remove();
1 change: 0 additions & 1 deletion src/fs/files/fileToRemove.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/fs/files/fresh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am fresh and young
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This is a file with a wrong filename

Hello from **markdown**!
Hello from **markdown**!
21 changes: 21 additions & 0 deletions src/fs/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { readdir, access } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";

const list = async () => {
// Write your code here
const directoryURL = new URL("./files/", import.meta.url);
const directory = fileURLToPath(directoryURL);
const errorMessage = "FS operation failed";
try {
try {
await access(directory);
} catch (e) {
throw new Error(errorMessage);
}
const fileNames = await readdir(directory);
console.log(fileNames);
} catch (e) {
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
console.log(e);
}
}
};

await list();
21 changes: 21 additions & 0 deletions src/fs/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { readFile, access } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";

const read = async () => {
// Write your code here
const fileURL = new URL("./files/fileToRead.txt", import.meta.url);
const file = fileURLToPath(fileURL);
const errorMessage = "FS operation failed";
try {
try {
await access(file);
} catch (e) {
throw new Error(errorMessage);
}
const contents = await readFile(file, { encoding: "utf8" });
console.log(contents);
} catch (e) {
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
console.log(e);
}
}
};

await read();
27 changes: 27 additions & 0 deletions src/fs/rename.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import { rename as renamePromise, access } from "node:fs/promises";
import { URL, fileURLToPath } from "node:url";

const rename = async () => {
// Write your code here
const oldPathURL = new URL("./files/wrongFilename.txt", import.meta.url);
const newPathURL = new URL("./files/properFilename.md", import.meta.url);
const oldPath = fileURLToPath(oldPathURL);
const newPath = fileURLToPath(newPathURL);
const errorMessage = "FS operation failed";
try {
try {
await access(oldPath);
} catch (e) {
throw new Error(errorMessage);
}
await access(newPath);
throw new Error(errorMessage);
} catch (e) {
if (e instanceof Error && e.message === errorMessage) {
console.log(e.message);
} else {
try {
await renamePromise(oldPath, newPath);
} catch (e) {
console.log(e);
}
}
}
};

await rename();
21 changes: 21 additions & 0 deletions src/hash/calcHash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { createHash } from "node:crypto";
import { createReadStream } from "node:fs";
import { URL, fileURLToPath } from "node:url";

const calculateHash = async () => {
// Write your code here
const fileUrl = new URL(
"./files/fileToCalculateHashFor.txt",
import.meta.url,
);
const filePath = fileURLToPath(fileUrl);

const hash = createHash("sha256");

hash.on("readable", () => {
const data = hash.read();
if (data) {
console.log(data.toString("hex"));
}
});

const fileStream = createReadStream(filePath);
fileStream.pipe(hash);
};

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

This file was deleted.

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

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const random = Math.random();

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

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

console.log(`Path to current file is ${__filename}`);
console.log(`Path to current directory is ${__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 { unknownObject, myServer };
1 change: 1 addition & 0 deletions src/streams/files/fileToWrite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Very well
8 changes: 8 additions & 0 deletions src/streams/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { createReadStream } from "node:fs";
import { URL, fileURLToPath } from "node:url";
const read = async () => {
// Write your code here
const fileURL = new URL("./files/fileToRead.txt", import.meta.url);
const filePath = fileURLToPath(fileURL);

const readableStream = createReadStream(filePath, { encoding: "utf-8" });

readableStream.pipe(process.stdout);
};

await read();
9 changes: 9 additions & 0 deletions src/streams/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { Transform } from "node:stream";
const transform = async () => {
// Write your code here
const reverseStream = new Transform({
transform(chunk, _, callback) {
const reversed = chunk.toString().split("").reverse().join("");
callback(null, reversed);
},
});

process.stdin.pipe(reverseStream).pipe(process.stdout);
};

await transform();
8 changes: 8 additions & 0 deletions src/streams/write.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { createWriteStream } from "node:fs";
import { URL, fileURLToPath } from "node:url";
const write = async () => {
// Write your code here
const fileURL = new URL("./files/fileToWrite.txt", import.meta.url);
const filePath = fileURLToPath(fileURL);

const writableStream = createWriteStream(filePath, { encoding: "utf-8" });

process.stdin.pipe(writableStream);
};

await write();
Loading