Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
'env': {
'commonjs': true,
'es2022': true,
'es2021': true,
'node': true
},
'extends': 'eslint:recommended',
Expand Down
Binary file added 01-read-file/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions 01-read-file/index.js
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion 01-read-file/text.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Нет хуже причины для выбора имени с, чем та, что имена a и b уже заняты.
Нет хуже причины для выбора имени с, чем та, что имена a и b уже заняты.
28 changes: 28 additions & 0 deletions 02-write-file/index.js
Original file line number Diff line number Diff line change
@@ -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();

1 change: 1 addition & 0 deletions 02-write-file/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jj]
11 changes: 11 additions & 0 deletions 03-files-in-folder/index.js
Original file line number Diff line number Diff line change
@@ -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);
});