diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..1cc188d4f Binary files /dev/null and b/.DS_Store differ 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/.DS_Store b/01-read-file/.DS_Store new file mode 100644 index 000000000..9b895f663 Binary files /dev/null and b/01-read-file/.DS_Store differ 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 diff --git a/01-read-file/text.txt b/01-read-file/text.txt index 536528ae3..1a0c71c61 100644 --- a/01-read-file/text.txt +++ b/01-read-file/text.txt @@ -1 +1 @@ -Нет хуже причины для выбора имени с, чем та, что имена a и b уже заняты. +Нет хуже причины для выбора имени с, чем та, что имена a и b уже заняты. \ No newline at end of file diff --git a/02-write-file/index.js b/02-write-file/index.js index e69de29bb..037a2c35f 100644 --- a/02-write-file/index.js +++ b/02-write-file/index.js @@ -0,0 +1,28 @@ +const fs = require('fs'); +const path = require('path'); + +const writeFile = () => { + 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) => { + 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 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