Skip to content

feat: file compression#216

Open
DmytroMykoliv wants to merge 3 commits intomate-academy:masterfrom
DmytroMykoliv:develop
Open

feat: file compression#216
DmytroMykoliv wants to merge 3 commits intomate-academy:masterfrom
DmytroMykoliv:develop

Conversation

@DmytroMykoliv
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great work on implementing the server and handling the form data. However, changes are needed to address a few critical issues that cause runtime errors and fail to meet core requirements.

Here's what needs to be fixed:

  1. Incorrect File Extensions: The server generates files with .gzip and .deflate extensions, but the requirements specify .gz and .dfl respectively.
  2. Runtime Crash on Cleanup: Your code attempts to call .destroy() on the compressor function itself, not the stream instance it creates. This will cause a TypeError and crash the server if a client disconnects. You need to save the stream instance to a variable and call destroy on that.
  3. Synchronous File Reading: The index.html file is served using fs.readFileSync, which blocks the event loop. A core requirement is to use streams for I/O, so please use fs.createReadStream() and pipe it to the response instead.

Once these issues are addressed, your solution will be in great shape!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Disposition': `attachment; filename=${file.originalFilename}.${compressionType}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirement specifies the compressed file extensions should be .gz for gzip and .dfl for deflate. Currently, you are using the compressionType directly, which results in .gzip and .deflate. You might want to store the correct extension in your compressMap and use it here.


req.on('close', () => {
readStream.destroy();
compressor.destroy();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will cause a runtime error. The compressor variable here refers to the function from compressMap (e.g., () => zlib.createGzip()), not the actual stream instance. A function doesn't have a .destroy() method. You need to save the stream instance created by compressor() inside the pipeline to a variable and then call .destroy() on that variable here.

return;
}

const html = fs.readFileSync(realPath);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires using streams for I/O operations. fs.readFileSync reads the entire file into memory before sending it, which is not a stream-based approach. Consider using fs.createReadStream() and piping it to the response stream (res) to fulfill this requirement.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job fixing the file extension issues and the runtime crash from the last review! The compression logic is now working perfectly.

However, this requires changes because the server no longer serves the index.html file. Currently, it responds with a static "OK" string instead of the actual file content. This is a critical issue as it prevents the main form from being displayed, which blocks the core functionality of the application.

To fix this, please update your code in src/createServer.js to use a readable stream to send the file. You can do this by replacing res.end('OK'); with a pipeline like fs.createReadStream(realPath).pipe(res);.

Once that's fixed, your solution should be all set!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


res.statusCode = 200;
res.setHeader('Content-Type', mimeType);
res.end('OK');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line sends a static "OK" string as the response body, but the task requires serving the actual HTML file content. You should use a readable stream to send the file located at realPath to the response. Consider using fs.createReadStream() and piping its output to the res object.

@@ -124,7 +127,7 @@ describe('createServer', () => {
headers: formData.getHeaders(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line sends a static "OK" string as the response body. According to the task requirements and previous feedback, you should be streaming the actual file content to the response. Please use fs.createReadStream() and pipe it to the res object here.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this submission! You've successfully addressed the previous feedback by correctly serving the index.html file using a readable stream. Your implementation is clean, efficient, and meets all the project requirements, including robust error handling and the proper use of streams for compression. The server now functions perfectly, and all tests are passing. This is a fantastic implementation, and I am approving your solution.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants