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
1 change: 1 addition & 0 deletions src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const parseArgs = () => {
if (i + 2 < process.argv.length) process.stdout.write(', ');
}
};
parseArgs();
1 change: 1 addition & 0 deletions src/cli/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const parseEnv = () => {
if (n.startsWith('RSS_')) arr.push(`${n}=${process.env[n]}`);
console.log(arr.join('; '));
};
parseEnv();
12 changes: 10 additions & 2 deletions src/cp/cp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { fork } from 'child_process';
import { join } from 'path';
import getGlobalVariables from '../global.js';

export const spawnChildProcess = async (args) => {
// Write your code here
};
const { __dirname } = getGlobalVariables(import.meta.url);
const pathToChildProcess = join(__dirname, '/files/script.js');
fork(pathToChildProcess, args);
};

spawnChildProcess(process.argv.slice(2));
1 change: 1 addition & 0 deletions src/fs/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export const copy = async () => {
}
}
};
copy();
1 change: 1 addition & 0 deletions src/fs/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const create = async () => {
if (fs.existsSync(file)) throw new Error('FS operation failed');
await fs.promises.writeFile(file, 'I am fresh and young', { flag: 'wx' });
};
create();
1 change: 1 addition & 0 deletions src/fs/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const remove = async () => {
console.log('Ну все, чё, нету больше файлика!');
});
};
remove();
1 change: 1 addition & 0 deletions src/fs/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const read = async () => {
console.log(data.toString());
});
};
read();
1 change: 1 addition & 0 deletions src/fs/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const rename = async () => {
}
);
};
rename();
3 changes: 2 additions & 1 deletion src/hash/calcHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const calculateHash = async () => {
const hashSum = crypto.createHash('sha256');
hashSum.update(fileBuffer);
const hex = hashSum.digest('hex');
return hex;
console.log(hex);
};
console.log(await calculateHash());
1 change: 1 addition & 0 deletions src/streams/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import fs from 'fs';
export const read = async () => {
fs.createReadStream('files/fileToRead.txt').pipe(process.stdout);
};
read();
1 change: 1 addition & 0 deletions src/streams/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const transform = async () => {
const T = new T();
process.stdin.pipe(T).pipe(process.stdout);
};
transform();
1 change: 1 addition & 0 deletions src/streams/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export const write = async () => {
const writeStream = fs.createWriteStream(into);
process.stdin.pipe(writeStream);
};
write();
26 changes: 24 additions & 2 deletions src/wt/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
import worker_threads from 'worker_threads';
import path from 'path';
import { fileURLToPath } from 'url';

export const performCalculations = async () => {
// Write your code here
};
const arr = [];
const from = path.join(fileURLToPath(import.meta.url), '..', 'worker.js');
for (let i = 0; i < process.env.NUMBER_OF_PROCESSORS; i++) {
arr.push(new worker_threads.Worker(from));
arr[i].postMessage(10 + i);
}
const res = new Array(arr.length);
for (let i = 0; i < arr.length; i++) {
res[i] = new Promise((resolve) => {
arr[i].on('message', (obj) => {
resolve((res[i] = obj));
});
arr[i].on('error', () => {
resolve((res[i] = { status: 'error', data: null }));
});
});
}
console.log(await Promise.all(res));
};
performCalculations();
14 changes: 10 additions & 4 deletions src/wt/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// n should be received from main thread
export const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2);
import wt from 'worker_threads';

export const nthFibonacci = (n) =>
n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2);

export const sendResult = () => {
// This function sends result of nthFibonacci computations to main thread
};
wt.parentPort.on('message', (n) => {
wt.parentPort.postMessage({ status: 'resolved', data: nthFibonacci(n) });
});
};

sendResult();
25 changes: 23 additions & 2 deletions src/zip/compress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import zlib from 'zlib';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

export const compress = async () => {
// Write your code here
};
const from = path.join(
fileURLToPath(import.meta.url),
'..',
'files',
'fileToCompress.txt'
);
const to = path.join(
fileURLToPath(import.meta.url),
'..',
'files',
'archive.gz'
);
const fromWhat = fs.createReadStream(from);
const toWhat = fs.createWriteStream(to);
const zip = zlib.createGzip();
fromWhat.pipe(zip).pipe(toWhat);
};
compress();
25 changes: 23 additions & 2 deletions src/zip/decompress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import zlib from 'zlib';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

export const decompress = async () => {
// Write your code here
};
const from = path.join(
fileURLToPath(import.meta.url),
'..',
'files',
'archive.gz'
);
const to = path.join(
fileURLToPath(import.meta.url),
'..',
'files',
'fileToCompress.txt'
);
const fromWhat = fs.createReadStream(from);
const toWhat = fs.createWriteStream(to);
const zip = zlib.createUnzip();
fromWhat.pipe(zip).pipe(toWhat);
};
decompress();