Repository navigation
Conversation
| console.log( | ||
| argv | ||
| .filter((entity) => entity.match(/--\w*/)) | ||
| .map((item) => `${item.slice(2)} is ${argv[argv.indexOf(item) + 1]}`) |
There was a problem hiding this comment.
Although this is correct implementation, I believe it is very inefficient due to indexOf call for each iteration of map.
| .catch(() => { | ||
| callback(); | ||
| }) | ||
| .then(async () => { |
There was a problem hiding this comment.
When files folder does not exist, the promise still chains to then construction and creates empty files_copy folder. This is not right behaviour. Since it print FS operation failed twice, I will not deduct any point but the code has confusing semantics.
| .then(async () => { | ||
| await fsPromises | ||
| .access(pathTo) | ||
| .then(() => callback()) |
| await fsPromises | ||
| .access(pathTo) | ||
| .then(() => callback()) | ||
| .catch(() => { |
There was a problem hiding this comment.
Do not create folder when error occurs and you capture it in catch clause.
| export const create = async () => { | ||
| await fsPromises | ||
| .access(pathToFile) | ||
| .catch(async () => { |
There was a problem hiding this comment.
I think you mistakenly swapped then with catch
| await remove(); No newline at end of file | ||
| function callback() { | ||
| try { | ||
| throw new Error("FS operation failed"); |
There was a problem hiding this comment.
Why do you throw Error inside try-catch block? When error occurs you would like to see stack trace and error object captures that information.
|
|
||
| await list(); No newline at end of file | ||
| function callback() { | ||
| try { |
| .then((fileBuffer) => { | ||
| console.log(createHash("sha256").update(fileBuffer).digest("hex")); | ||
| }) | ||
| .catch((error) => { |
There was a problem hiding this comment.
This is the correct way of handling error.
| ) | ||
| }) | ||
|
|
||
| console.log(await Promise.all(result)); |
There was a problem hiding this comment.
It is better to use here Promise.allSettled because Promise.allSettled() resolves when all the given promises have either fulfilled or rejected.
In your case, using Promise.all() resolves only when all given promises resolve, and will reject immediately if any of the promises reject (or non-promises throw an error).
Please read more here: https://www.designcise.com/web/tutorial/whats-the-difference-between-promise-all-and-promise-allsettled-in-javascript
Self-evaluation:
File system (src/fs)
+6 create.js implemented properly
+10 copy.js implemented properly
+10 rename.js implemented properly
+6 delete.js implemented properly
+6 list.js implemented properly
+6 read.js implemented properly
Command line interface(src/cli)
+6 env.js implemented properly
+6 args.js implemented properly
Modules(src/modules)
+20 cjsToEsm.cjs refactored properly
Hash (src/hash)
+10 calcHash.js implemented properly
Streams (src/streams)
+10 read.js implemented properly
+10 write.js implemented properly
+10 transform.js implemented properly
Zlib (src/zip)
+10 compress.js implemented properly
+10 decompress.js implemented properly
Worker Threads (src/wt)
+10 worker.js implemented properly
+30 main.js implemented properly
Child Processes (src/cp)
+10 spawns child process
+10 child process stdin receives input from master process stdin
+10 child process stdout sends data to master process stdout