From c271fd5b38b1435d5de074a63ee85f15bec97693 Mon Sep 17 00:00:00 2001 From: natalliadk Date: Sun, 7 May 2023 15:35:45 +0300 Subject: [PATCH 1/3] finish task 1 and install eslint --- .eslintrc.js | 2 +- 01-read-file/index.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 664f4417f..04c1c8b70 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { 'env': { 'commonjs': true, - 'es2022': true, + 'es2021': true, 'node': true }, 'extends': 'eslint:recommended', diff --git a/01-read-file/index.js b/01-read-file/index.js index e69de29bb..56542a3c3 100644 --- a/01-read-file/index.js +++ b/01-read-file/index.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const path = require('path'); + +const readFile = () => { + const filePath = path.join(__dirname, './text.txt'); + const fileStream = fs.createReadStream(filePath, { encoding: 'utf8' }); + + logChunks(fileStream); +}; + +async function logChunks(readable) { + for await (const chunk of readable) { + console.log(chunk); + } +} + +readFile(); \ No newline at end of file From 336aefc88483d579764015c9a4d6438e7ee30840 Mon Sep 17 00:00:00 2001 From: natalliadk Date: Sun, 7 May 2023 17:44:54 +0300 Subject: [PATCH 2/3] finish task 2 --- 02-write-file/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/02-write-file/index.js b/02-write-file/index.js index e69de29bb..681216818 100644 --- a/02-write-file/index.js +++ b/02-write-file/index.js @@ -0,0 +1,25 @@ +const fs = require('fs'); +const path = require('path'); + +const writeFile = () => { + const filePath = path.join(__dirname, './text.txt'); + + const file = fs.createWriteStream(filePath, { flags: 'a' }); + + process.stdin.on('data', (data) => { + if (data.toString().trim() === 'exit') { + console.log('Bye...'); + process.exit(); + } + file.write(data); + }); + + process.on('SIGINT', () => { + console.log('\n'); + console.log('Bye...'); + process.exit(); + }); +}; + +writeFile(); + \ No newline at end of file From 393c31be4c35a9a2dae2861eee1ddca5b1eafee8 Mon Sep 17 00:00:00 2001 From: natalliadk Date: Thu, 11 May 2023 17:58:55 +0300 Subject: [PATCH 3/3] fix: add Hello --- .DS_Store | Bin 0 -> 8196 bytes 01-read-file/.DS_Store | Bin 0 -> 6148 bytes 01-read-file/text.txt | 2 +- 02-write-file/index.js | 3 +++ 02-write-file/text.txt | 1 + 03-files-in-folder/index.js | 11 +++++++++++ 6 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 01-read-file/.DS_Store create mode 100644 02-write-file/text.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1cc188d4f1299b5ad028704847e412bfdcf779fd GIT binary patch literal 8196 zcmeI1&u-H|5XNWQLY>m8EkbH9NWO4utE7Jr9FWqqJwyV82!aEk){foQ;CiDtAqpWV zcU}N4yaKPm8}KZg;G5m0jh&{KN~nTeX?NE4ezUW`Z0w9fM559TN<_;<TulnHZY9#%k46p}{)t#Mf41T2C7 zk^tWyTvWDYV+Y!*TL&7I0>Dn;v?}N$4^SG{*s`$$ZIu*0b@m{PRG1V)XgRLCJRG)c z>_A&BC!yse%*?`MC_>E+ovVhEC~Iq5OTZEsCBV7+EETDQti74Z-(w1^v8?;C^f89N zR@o zywbl>+r^gn)9D;p!QN0PO8)qabML(iMosksd zy;Dfd?2Z+;b9@)!V-t!xNor6Ry#PLV-`DXuN%Xoo51(=#=HX!rx)Yv_j?`zHLfb_I zA*DI>&zzc9dlzb-+L)JPUPT-p`^hRNcrOj_jA?pERobCFdQ3Ii%Z?`AM_)7F%mk}p zBKwGxd+l@MV?M*WMHNk*-s+eTT?{oJuhAP2my~2@7R+bZ!)(sOI31H2))nX}*0xQ% z^ayqhQ3u(X6p=H9ef|TWEtbF~2uy12GUxw$ZVg@U<1T2B8PC!iU)^;n1^3RXo ze88M*yQl}KTzK3-TO~oG(s5Xoj>De*VTitqp{ywzJJ1$qQ0$8Ug~2wKz+WZs8$tO$ A7ytkO literal 0 HcmV?d00001 diff --git a/01-read-file/.DS_Store b/01-read-file/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9b895f66393a2c2e96e60c440949a2be2f231a34 GIT binary patch literal 6148 zcmeHKJ5B>Z41Fdk7SW`nL7Ee+#0{2cQ&7;r1yEQDP#^`1lyYyx5#jj*%7$%02-(v3 zIUd`y^Q6p-0m$;TI|mj3Dh@?aV?xwDIdv4lGoo0H9cnz{<#MyVn<(@bUHa`69`K9~ z_t^XX^=7-~oDy@vQNNqe0*-Nw6}>I4h&7(j>5lg@-VQP<^j5uRbk9}#alD)z#Oo?4 z$v`rY3?u`|z|SziJ6okXaZH^IBm>F77Xx}e6b{8EaB#GvgUVU};+$?1+WKVHoD$ds z4vw6mh^G=gRiecZPp7{`ToX7rdO9SU4~dmOn-{UwS-)5~q;X803?u_%2DJC3EcE_g z@h>yk { const filePath = path.join(__dirname, './text.txt'); + const ctaPhrase = 'Hello!'; + console.log(ctaPhrase); + const file = fs.createWriteStream(filePath, { flags: 'a' }); process.stdin.on('data', (data) => { diff --git a/02-write-file/text.txt b/02-write-file/text.txt new file mode 100644 index 000000000..3c77f5946 --- /dev/null +++ b/02-write-file/text.txt @@ -0,0 +1 @@ +jj] diff --git a/03-files-in-folder/index.js b/03-files-in-folder/index.js index e69de29bb..a1938cfcf 100644 --- a/03-files-in-folder/index.js +++ b/03-files-in-folder/index.js @@ -0,0 +1,11 @@ +const fs = require('fs'); +const path = require('path'); + +fs.readdir(path.join(__dirname, './secret-folder'), (err, files) => { + + console.log(1, err); + fs.stat(path.join(__dirname, './secret-folder'), (err, result) => { + }); + // const result = path.extname(path.join(__dirname, './secret-folder.jps')); + console.log(2, result); +}); \ No newline at end of file