From a6d30c23930ba6897aab4ab9a67285ab04e02cb1 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 10:51:39 +0400 Subject: [PATCH 01/28] feat: add file creating logic in create.js --- src/fs/create.js | 7 +++++++ src/fs/files/fresh.txt | 1 + 2 files changed, 8 insertions(+) create mode 100644 src/fs/files/fresh.txt diff --git a/src/fs/create.js b/src/fs/create.js index 6ede285599..ae32266b9c 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,5 +1,12 @@ +import { writeFile } from "node:fs/promises"; const create = async () => { // Write your code here + try { + const content = "I am fresh and young"; + await writeFile("./files/fresh.txt", content); + } catch (e) { + console.log(e); + } }; await create(); diff --git a/src/fs/files/fresh.txt b/src/fs/files/fresh.txt new file mode 100644 index 0000000000..205d704cb7 --- /dev/null +++ b/src/fs/files/fresh.txt @@ -0,0 +1 @@ +I am fresh and young \ No newline at end of file From 7f5624327fa1537dfbcaaf8eba8d6b072ab7c77f Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 12:14:17 +0400 Subject: [PATCH 02/28] feat: add logic for checking file existence before writing --- src/fs/create.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fs/create.js b/src/fs/create.js index ae32266b9c..12265074aa 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,11 +1,22 @@ -import { writeFile } from "node:fs/promises"; +import { writeFile, access } from "node:fs/promises"; const create = async () => { // Write your code here + const content = "I am fresh and young"; + const file = "./files/fresh.txt"; + const errorMessage = "FS operation failed"; try { - const content = "I am fresh and young"; - await writeFile("./files/fresh.txt", content); + await access(file); + throw new Error(errorMessage); } catch (e) { - console.log(e); + if (e instanceof Error && e.message === errorMessage) { + console.log(e.message); + } else { + try { + await writeFile(file, content); + } catch (e) { + console.log(e); + } + } } }; From a5c8d71145b3572bff1468f09a2765682d0bcebd Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 13:34:24 +0400 Subject: [PATCH 03/28] feat: implement folder coping If the folder already exists error is thrown --- src/fs/copy.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/fs/copy.js b/src/fs/copy.js index e226075b4c..70759dbdb3 100644 --- a/src/fs/copy.js +++ b/src/fs/copy.js @@ -1,5 +1,26 @@ +import { cp } from "node:fs/promises"; const copy = async () => { // Write your code here + const src = "./files/"; + const dest = "./files_copy"; + 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(); From 3434776bc7543d8d550a5491067e57fa75b75a7b Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 14:26:22 +0400 Subject: [PATCH 04/28] feat: implement file rename functionality --- .../{wrongFilename.txt => properFilename.md} | 2 +- src/fs/rename.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) rename src/fs/files/{wrongFilename.txt => properFilename.md} (61%) diff --git a/src/fs/files/wrongFilename.txt b/src/fs/files/properFilename.md similarity index 61% rename from src/fs/files/wrongFilename.txt rename to src/fs/files/properFilename.md index 38cca5db19..19f018e566 100644 --- a/src/fs/files/wrongFilename.txt +++ b/src/fs/files/properFilename.md @@ -1,3 +1,3 @@ # This is a file with a wrong filename -Hello from **markdown**! \ No newline at end of file +Hello from **markdown**! diff --git a/src/fs/rename.js b/src/fs/rename.js index b1d65b0c86..7ce34b0da7 100644 --- a/src/fs/rename.js +++ b/src/fs/rename.js @@ -1,5 +1,28 @@ +import { rename as renamePromise, access } from "node:fs/promises"; const rename = async () => { // Write your code here + const oldPath = "./files/wrongFilename.txt"; + const newPath = "./files/properFilename.md"; + 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(); From 1f3e63426063119cbd7fbc358666092b4d1659d2 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 15:01:09 +0400 Subject: [PATCH 05/28] in process... --- src/fs/delete.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/fs/delete.js b/src/fs/delete.js index a70b13766c..dd56b3198d 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -1,5 +1,31 @@ +import { unlink, access } from "node:fs/promises"; const remove = async () => { // Write your code here + const filePath = "./files/fileToRemove.txt"; + try { + try { + await access(filePath); + } catch (e) { + throw new Error(errorMessage); + } + await unlink(filePath); + console.log("File deleted successfully"); + } catch (e) { + if (e instanceof Error && e.message === errorMessage) { + console.log(e.message); + } else { + try { + await renamePromise(oldPath, newPath); + } catch (e) { + console.log(e); + } + } + if (err.code === "ENOENT") { + console.log("File does not exist"); + } else { + console.error("Error deleting file:", err); + } + } }; await remove(); From e0c66e1e8030abf0e9b627c766dd68a6e816cd16 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 17:51:08 +0400 Subject: [PATCH 06/28] fea: create file deletion function --- src/fs/delete.js | 25 +++++++++++++------------ src/fs/files/fileToRemove.txt | 1 - 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 src/fs/files/fileToRemove.txt diff --git a/src/fs/delete.js b/src/fs/delete.js index dd56b3198d..42b99c0680 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -2,28 +2,29 @@ import { unlink, access } from "node:fs/promises"; const remove = async () => { // Write your code here const filePath = "./files/fileToRemove.txt"; + const errorMessage = "FS operation failed"; try { + //check if file exists try { await access(filePath); } catch (e) { throw new Error(errorMessage); } - await unlink(filePath); - console.log("File deleted successfully"); + + //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 { - try { - await renamePromise(oldPath, newPath); - } catch (e) { - console.log(e); - } - } - if (err.code === "ENOENT") { - console.log("File does not exist"); - } else { - console.error("Error deleting file:", err); + console.log(e); } } }; diff --git a/src/fs/files/fileToRemove.txt b/src/fs/files/fileToRemove.txt deleted file mode 100644 index 43e64cd45c..0000000000 --- a/src/fs/files/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -How dare you! \ No newline at end of file From 30b4b9bf09dba867104cdd23376b96f3a8e33c01 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 19:20:23 +0400 Subject: [PATCH 07/28] feat: create function for listing filenames in files directory --- src/fs/list.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/fs/list.js b/src/fs/list.js index 0c0fa21f7e..918443d16d 100644 --- a/src/fs/list.js +++ b/src/fs/list.js @@ -1,5 +1,23 @@ +import { readdir, access } from "node:fs/promises"; const list = async () => { // Write your code here + const directory = "./files/"; + 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(); From 6aed636584fc38c516c6d79ea3722ee1559cc3df Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 19:33:40 +0400 Subject: [PATCH 08/28] feat: create file reader function --- src/fs/read.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/fs/read.js b/src/fs/read.js index e3938be563..6766ef6991 100644 --- a/src/fs/read.js +++ b/src/fs/read.js @@ -1,5 +1,24 @@ +import { readFile, access } from "node:fs/promises"; + const read = async () => { // Write your code here + const file = "./files/fileToRead.txt"; + 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(); From 611b5efe44740e9a070fc386e312f9de5ce809ab Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:07:52 +0400 Subject: [PATCH 09/28] fix: relative path for read.js --- src/fs/read.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fs/read.js b/src/fs/read.js index 6766ef6991..d63f49956d 100644 --- a/src/fs/read.js +++ b/src/fs/read.js @@ -1,8 +1,9 @@ import { readFile, access } from "node:fs/promises"; +import { URL } from "node:url"; const read = async () => { // Write your code here - const file = "./files/fileToRead.txt"; + const file = new URL("./files/fileToRead.txt", import.meta.url); const errorMessage = "FS operation failed"; try { try { From 7af0b19be9df546664871dc66c70562ee2ecd28d Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:12:05 +0400 Subject: [PATCH 10/28] fix: relative path for rename.js --- src/fs/rename.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fs/rename.js b/src/fs/rename.js index 7ce34b0da7..981e89bae7 100644 --- a/src/fs/rename.js +++ b/src/fs/rename.js @@ -1,8 +1,10 @@ import { rename as renamePromise, access } from "node:fs/promises"; +import { URL } from "node:url"; + const rename = async () => { // Write your code here - const oldPath = "./files/wrongFilename.txt"; - const newPath = "./files/properFilename.md"; + const oldPath = new URL("./files/wrongFilename.txt", import.meta.url); + const newPath = new URL("./files/properFilename.md", import.meta.url); const errorMessage = "FS operation failed"; try { try { From a13f24681362607a24d97cf2c8c9025d5c67766d Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:13:56 +0400 Subject: [PATCH 11/28] fix: relative path for list.js --- src/fs/list.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fs/list.js b/src/fs/list.js index 918443d16d..2f96d5d4ab 100644 --- a/src/fs/list.js +++ b/src/fs/list.js @@ -1,7 +1,9 @@ import { readdir, access } from "node:fs/promises"; +import { URL } from "node:url"; + const list = async () => { // Write your code here - const directory = "./files/"; + const directory = new URL("./files/", import.meta.url); const errorMessage = "FS operation failed"; try { try { From 3130a95ea7827475147b72c35def6ca904c31d8b Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:19:59 +0400 Subject: [PATCH 12/28] fix: relative path for delete.js --- src/fs/delete.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fs/delete.js b/src/fs/delete.js index 42b99c0680..7fc44caeac 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -1,7 +1,9 @@ import { unlink, access } from "node:fs/promises"; +import { URL } from "node:url"; + const remove = async () => { // Write your code here - const filePath = "./files/fileToRemove.txt"; + const filePath = new URL("./files/fileToRemove.txt", import.meta.url); const errorMessage = "FS operation failed"; try { //check if file exists From be8d470104f4b612e432291c05389b9b1f8f7646 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:24:02 +0400 Subject: [PATCH 13/28] fix: relative path for create.js --- src/fs/create.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fs/create.js b/src/fs/create.js index 12265074aa..2e115c8825 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,8 +1,10 @@ import { writeFile, access } from "node:fs/promises"; +import { URL } from "node:url"; + const create = async () => { // Write your code here const content = "I am fresh and young"; - const file = "./files/fresh.txt"; + const file = new URL("./files/fresh.txt", import.meta.url); const errorMessage = "FS operation failed"; try { await access(file); From a526346f5b7163d74e68d1db23d330c914e453a3 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 21:27:11 +0400 Subject: [PATCH 14/28] fix: relative path for copy.js --- src/fs/copy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fs/copy.js b/src/fs/copy.js index 70759dbdb3..8f64d1e32b 100644 --- a/src/fs/copy.js +++ b/src/fs/copy.js @@ -1,8 +1,9 @@ import { cp } from "node:fs/promises"; +import { URL } from "node:url"; const copy = async () => { // Write your code here - const src = "./files/"; - const dest = "./files_copy"; + const src = new URL("./files/", import.meta.url); + const dest = new URL("./files_copy", import.meta.url); const errorMessage = "FS operation failed"; try { try { From 538ffd5b0ef0dd1e865beb7c523b266573424e18 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 22:58:19 +0400 Subject: [PATCH 15/28] feat: implement console of env variables starting on RSS_ --- src/cli/env.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/env.js b/src/cli/env.js index e3616dc8e7..7d0f84dafa 100644 --- a/src/cli/env.js +++ b/src/cli/env.js @@ -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(); From fa0502cd734a165751b4299dac74adca6287fcfe Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sat, 25 Oct 2025 23:49:20 +0400 Subject: [PATCH 16/28] feat: implement console of cli arguments via args.js --- src/cli/args.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cli/args.js b/src/cli/args.js index 9e3622f791..935745ac51 100644 --- a/src/cli/args.js +++ b/src/cli/args.js @@ -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(); From 559cc77b5fa6534dcd341c37f0525d7d38faf677 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 12:34:03 +0400 Subject: [PATCH 17/28] refac: rewrite cjsToEsm.cjs into esm module --- src/modules/cjsToEsm.cjs | 34 ---------------------------------- src/modules/esm.mjs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 src/modules/cjsToEsm.cjs create mode 100644 src/modules/esm.mjs diff --git a/src/modules/cjsToEsm.cjs b/src/modules/cjsToEsm.cjs deleted file mode 100644 index 089bd2db13..0000000000 --- a/src/modules/cjsToEsm.cjs +++ /dev/null @@ -1,34 +0,0 @@ -const path = require('node:path'); -const { release, version } = require('node:os'); -const { createServer: createServerHttp } = require('node:http'); - -require('./files/c.cjs'); - -const random = Math.random(); - -const unknownObject = random > 0.5 ? require('./files/a.json') : require('./files/b.json'); - -console.log(`Release ${release()}`); -console.log(`Version ${version()}`); -console.log(`Path segment separator is "${path.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'); -}); - -module.exports = { - unknownObject, - myServer, -}; diff --git a/src/modules/esm.mjs b/src/modules/esm.mjs new file mode 100644 index 0000000000..607b0e4f90 --- /dev/null +++ b/src/modules/esm.mjs @@ -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 }; From c36e7ff35bf60b2c1649199541c9520f551040e1 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 14:00:43 +0400 Subject: [PATCH 18/28] feat: console SHA256 hash for a given file --- src/hash/calcHash.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/hash/calcHash.js b/src/hash/calcHash.js index e37c17ed62..dbf897d486 100644 --- a/src/hash/calcHash.js +++ b/src/hash/calcHash.js @@ -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(); From b450e07c3ebd74e9c1e36d4148b45d616a1d4a43 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 14:51:12 +0400 Subject: [PATCH 19/28] refac: use fileURLToPath in fs files for multiple OS compatabil --- src/fs/copy.js | 8 +++++--- src/fs/create.js | 5 +++-- src/fs/delete.js | 5 +++-- src/fs/list.js | 5 +++-- src/fs/read.js | 5 +++-- src/fs/rename.js | 8 +++++--- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/fs/copy.js b/src/fs/copy.js index 8f64d1e32b..129ef1a134 100644 --- a/src/fs/copy.js +++ b/src/fs/copy.js @@ -1,9 +1,11 @@ import { cp } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const copy = async () => { // Write your code here - const src = new URL("./files/", import.meta.url); - const dest = new URL("./files_copy", import.meta.url); + 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 { diff --git a/src/fs/create.js b/src/fs/create.js index 2e115c8825..a22c8fea84 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,10 +1,11 @@ import { writeFile, access } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const create = async () => { // Write your code here const content = "I am fresh and young"; - const file = new URL("./files/fresh.txt", import.meta.url); + const fileURL = new URL("./files/fresh.txt", import.meta.url); + const file = fileURLToPath(fileURL); const errorMessage = "FS operation failed"; try { await access(file); diff --git a/src/fs/delete.js b/src/fs/delete.js index 7fc44caeac..3919f20cb1 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -1,9 +1,10 @@ import { unlink, access } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const remove = async () => { // Write your code here - const filePath = new URL("./files/fileToRemove.txt", import.meta.url); + const fileURL = new URL("./files/fileToRemove.txt", import.meta.url); + const filePath = fileURLToPath(fileURL); const errorMessage = "FS operation failed"; try { //check if file exists diff --git a/src/fs/list.js b/src/fs/list.js index 2f96d5d4ab..ae425f16e9 100644 --- a/src/fs/list.js +++ b/src/fs/list.js @@ -1,9 +1,10 @@ import { readdir, access } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const list = async () => { // Write your code here - const directory = new URL("./files/", import.meta.url); + const directoryURL = new URL("./files/", import.meta.url); + const directory = fileURLToPath(directoryURL); const errorMessage = "FS operation failed"; try { try { diff --git a/src/fs/read.js b/src/fs/read.js index d63f49956d..a7642f4d2f 100644 --- a/src/fs/read.js +++ b/src/fs/read.js @@ -1,9 +1,10 @@ import { readFile, access } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const read = async () => { // Write your code here - const file = new URL("./files/fileToRead.txt", import.meta.url); + const fileURL = new URL("./files/fileToRead.txt", import.meta.url); + const file = fileURLToPath(fileURL); const errorMessage = "FS operation failed"; try { try { diff --git a/src/fs/rename.js b/src/fs/rename.js index 981e89bae7..88b7240ad5 100644 --- a/src/fs/rename.js +++ b/src/fs/rename.js @@ -1,10 +1,12 @@ import { rename as renamePromise, access } from "node:fs/promises"; -import { URL } from "node:url"; +import { URL, fileURLToPath } from "node:url"; const rename = async () => { // Write your code here - const oldPath = new URL("./files/wrongFilename.txt", import.meta.url); - const newPath = new URL("./files/properFilename.md", import.meta.url); + 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 { From f3dcfba57c300c46dbe1b24bd4be6c8048a7766c Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 15:12:10 +0400 Subject: [PATCH 20/28] feat: implement compressing a file --- src/zip/compress.js | 14 ++++++++++++++ src/zip/files/archive.gz | Bin 0 -> 32 bytes 2 files changed, 14 insertions(+) create mode 100644 src/zip/files/archive.gz diff --git a/src/zip/compress.js b/src/zip/compress.js index d55209587e..75744fd552 100644 --- a/src/zip/compress.js +++ b/src/zip/compress.js @@ -1,5 +1,19 @@ +import { createReadStream, createWriteStream } from "node:fs"; +import { createGzip } from "node:zlib"; +import { pipeline } from "node:stream/promises"; +import { URL, fileURLToPath } from "node:url"; const compress = async () => { // Write your code here + const inputFileURL = new URL("./files/fileToCompress.txt", import.meta.url); + const input = fileURLToPath(inputFileURL); + const outputFileURL = new URL("./files/archive.gz", import.meta.url); + const output = fileURLToPath(outputFileURL); + + const gzip = createGzip(); + + const source = createReadStream(input); + const destination = createWriteStream(output); + await pipeline(source, gzip, destination); }; await compress(); diff --git a/src/zip/files/archive.gz b/src/zip/files/archive.gz new file mode 100644 index 0000000000000000000000000000000000000000..87e36da4f0b95f5488a28cc58c6c716430c823a8 GIT binary patch literal 32 jcmb2|=3oE==Hhebbv3+n^} Date: Sun, 26 Oct 2025 15:26:51 +0400 Subject: [PATCH 21/28] feat: implement decompression of a file --- src/zip/compress.js | 7 ++++++- src/zip/decompress.js | 20 ++++++++++++++++++++ src/zip/files/archive.gz | Bin 32 -> 33 bytes src/zip/files/fileToCompress.txt | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/zip/compress.js b/src/zip/compress.js index 75744fd552..50b2b3c5b9 100644 --- a/src/zip/compress.js +++ b/src/zip/compress.js @@ -13,7 +13,12 @@ const compress = async () => { const source = createReadStream(input); const destination = createWriteStream(output); - await pipeline(source, gzip, destination); + try { + await pipeline(source, gzip, destination); + console.log("Compression complete!"); + } catch (err) { + console.error("Compression failed:", err); + } }; await compress(); diff --git a/src/zip/decompress.js b/src/zip/decompress.js index 8aaf26c8a4..15fc5aab0d 100644 --- a/src/zip/decompress.js +++ b/src/zip/decompress.js @@ -1,5 +1,25 @@ +import { createReadStream, createWriteStream } from "node:fs"; +import { createGunzip } from "node:zlib"; +import { pipeline } from "node:stream/promises"; +import { URL, fileURLToPath } from "node:url"; + const decompress = async () => { // Write your code here + const inputFileURL = new URL("./files/archive.gz", import.meta.url); + const input = fileURLToPath(inputFileURL); + + const outputFileURL = new URL("./files/fileToCompress.txt", import.meta.url); + const output = fileURLToPath(outputFileURL); + + const gunzip = createGunzip(); + const source = createReadStream(input); + const destination = createWriteStream(output); + try { + await pipeline(source, gunzip, destination); + console.log("Decompression complete!"); + } catch (err) { + console.error("Decompression failed:", err); + } }; await decompress(); diff --git a/src/zip/files/archive.gz b/src/zip/files/archive.gz index 87e36da4f0b95f5488a28cc58c6c716430c823a8..f04ad97dcf0ddaba44de8322e39c2c352b68ef15 100644 GIT binary patch delta 16 XcmY#ToFK;igo&X+*q?=$fq?-49tZ-= delta 15 WcmY#Xm>|Z*!m#RT{A?Zu1_l5fumg(# diff --git a/src/zip/files/fileToCompress.txt b/src/zip/files/fileToCompress.txt index 4d4efc82fe..c05cafdce9 100644 --- a/src/zip/files/fileToCompress.txt +++ b/src/zip/files/fileToCompress.txt @@ -1 +1 @@ -Compress me! \ No newline at end of file +Compress me! From 40afeeded1f6d290f25b6b99d2a6bf91d6020ecc Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 17:52:25 +0400 Subject: [PATCH 22/28] feat: create readbale stream --- src/streams/read.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/streams/read.js b/src/streams/read.js index e3938be563..dee73b81b4 100644 --- a/src/streams/read.js +++ b/src/streams/read.js @@ -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(); From 0cc14107cf50ea4554cc5d995da91212832a244a Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 18:03:57 +0400 Subject: [PATCH 23/28] feat: create writable stream --- src/streams/files/fileToWrite.txt | 1 + src/streams/write.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/streams/files/fileToWrite.txt b/src/streams/files/fileToWrite.txt index e69de29bb2..2ec30825be 100644 --- a/src/streams/files/fileToWrite.txt +++ b/src/streams/files/fileToWrite.txt @@ -0,0 +1 @@ +Very well diff --git a/src/streams/write.js b/src/streams/write.js index 84aa11e7cb..f8ba95089c 100644 --- a/src/streams/write.js +++ b/src/streams/write.js @@ -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(); From 1ccec0a98900bce2d16c6b18994f8ef973f59c43 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 18:19:00 +0400 Subject: [PATCH 24/28] feat: implement transforming input in reversed order --- src/streams/transform.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/streams/transform.js b/src/streams/transform.js index 9e6c15fe84..fa1f8c1c3a 100644 --- a/src/streams/transform.js +++ b/src/streams/transform.js @@ -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(); From 6cf32acdc4cd795c0820d7c7798d78070317891f Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 23:13:05 +0400 Subject: [PATCH 25/28] feat(wt): pass fibonacci result to main thread --- src/wt/worker.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wt/worker.js b/src/wt/worker.js index 405595394d..ef15040e99 100644 --- a/src/wt/worker.js +++ b/src/wt/worker.js @@ -1,8 +1,14 @@ +import { parentPort, workerData } from "node:worker_threads"; // n should be received from main thread -const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); +const nthFibonacci = (n) => + n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); const sendResult = () => { // This function sends result of nthFibonacci computations to main thread + + const result = nthFibonacci(workerData); + + parentPort.postMessage(result); }; sendResult(); From 8835ef1146b68652800e15c0ee6898df0cc53ea0 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Sun, 26 Oct 2025 23:37:18 +0400 Subject: [PATCH 26/28] feat(wt): import cpu to get the number of cpus --- src/wt/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wt/main.js b/src/wt/main.js index e2ef054d41..79754360d6 100644 --- a/src/wt/main.js +++ b/src/wt/main.js @@ -1,5 +1,8 @@ +import { cpus } from "node:os"; const performCalculations = async () => { // Write your code here + const numCPUs = cpus().length; + console.log(numCPUs); }; await performCalculations(); From e8c112e9d51d356331213a70efc2adbac5a4053c Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Mon, 27 Oct 2025 00:23:37 +0400 Subject: [PATCH 27/28] feat: create worker threads based on cpu cores quantity --- src/wt/main.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wt/main.js b/src/wt/main.js index 79754360d6..4ca43e6b17 100644 --- a/src/wt/main.js +++ b/src/wt/main.js @@ -1,8 +1,32 @@ import { cpus } from "node:os"; +import { Worker } from "node:worker_threads"; +import { URL, fileURLToPath } from "node:url"; + const performCalculations = async () => { // Write your code here const numCPUs = cpus().length; - console.log(numCPUs); + const workerURL = new URL("./worker.js", import.meta.url); + const workerPath = fileURLToPath(workerURL); + + const promises = Array.from({ length: numCPUs }, (_, i) => { + const workerData = 10 + i; + const worker = new Worker(workerPath, { workerData }); + + return new Promise((resolve) => { + worker.on("message", (data) => { + resolve({ status: "resolved", data }); + }); + worker.on("error", () => { + resolve({ status: "error", data: null }); + }); + worker.on("exit", (code) => { + if (code !== 0) resolve({ status: "error", data: null }); + }); + }); + }); + + const resultsArray = await Promise.all(promises); + console.log(resultsArray); }; await performCalculations(); From 0a49c3663105e08c397d2ccb0c7011b3ae9942a0 Mon Sep 17 00:00:00 2001 From: Irakli Ambroladze Date: Mon, 27 Oct 2025 01:51:59 +0400 Subject: [PATCH 28/28] feat: spawn child process --- src/cp/cp.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cp/cp.js b/src/cp/cp.js index 72c6addc9c..7a27d9c477 100644 --- a/src/cp/cp.js +++ b/src/cp/cp.js @@ -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"]);