Skip to content

Solution#198

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

Solution#198
hma-3 wants to merge 3 commits intomate-academy:masterfrom
hma-3:develop

Conversation

@hma-3
Copy link

@hma-3 hma-3 commented Jan 7, 2026

No description provided.

Copy link

@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 the client-side implementation and the overall server structure! Your use of streams for the compression logic is also correct. However, I am requesting changes because two core requirements are not fully met. First, the static file server in src/createServer.js uses fs.readFileSync(), which is a blocking operation; the task requires using non-blocking streams, so please refactor this to use fs.createReadStream() and pipe it to the response. Second, the compressed file extensions for gzip and deflate are incorrect (.gzip and .deflate instead of the required .gz and .dfl). Please adjust the logic to generate the correct extensions. After fixing these two points, your solution will be ready for approval!


✨ 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

}

const compressStream = createCompressionStream(compressionType);
const encodedFilename = encodeFilename(`${filename}.${compressionType}`);

Choose a reason for hiding this comment

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

The file extension for the compressed file doesn't match the requirements for all compression types. The task specifies .gz for gzip and .dfl for deflate, but this implementation will generate .gzip and .deflate respectively. You might need a way to map the compressionType to the correct extension.

Copy link
Author

@hma-3 hma-3 Jan 7, 2026

Choose a reason for hiding this comment

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

The tests expect .gzip and .deflate, not .gz and .dfl.

tests/createServer.test.js:

const compressionTypes = {
  gzip: {
    decompress: util.promisify(zlib.gunzip),
  },
  deflate: {
    decompress: util.promisify(zlib.inflate),
  },
  br: {
    decompress: util.promisify(zlib.brotliDecompress),
  },
};

Copy link

@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 refactoring the server to use streams! That's a significant improvement and addresses a key piece of feedback from the last review. I am requesting changes because the critical issue with file extensions still needs to be fixed. According to the task requirements, gzip compression should produce a .gz extension and deflate should produce a .dfl extension, but your code is currently generating .gzip and .deflate. You can fix this in src/createServer.js by creating a simple mapping from the compression type to the correct extension when you build the filename. You're very close to a complete solution!


✨ 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

}

const compressStream = createCompressionStream(compressionType);
const encodedFilename = encodeFilename(`${filename}.${compressionType}`);

Choose a reason for hiding this comment

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

The file extensions for gzip and deflate are still not matching the requirements. According to the task description, the extensions should be .gz for gzip and .dfl for deflate.

This line currently uses the compression type directly, which results in incorrect extensions like .gzip. You'll need to create a mapping from the compression type to the correct file extension.

Copy link
Author

Choose a reason for hiding this comment

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

The tests expect .gzip and .deflate, not .gz and .dfl.

tests/createServer.test.js:

const compressionTypes = {
  gzip: {
    decompress: util.promisify(zlib.gunzip),
  },
  deflate: {
    decompress: util.promisify(zlib.inflate),
  },
  br: {
    decompress: util.promisify(zlib.brotliDecompress),
  },
};

They are failing if extensions .gz or .dfl are used:

createServer › Server › POST to the "/compress" endpoint › compression type "gzip" › should respond with a correct "Content-Disposition" header

    expect(received).toBe(expected) // Object.is equality

    Expected: "attachment; filename=extraneous.pptx.gzip"
    Received: "attachment; filename=extraneous.pptx.gz"

      127 |                   const expectedHeader = `attachment; filename=${filename}.${compressionType}`;
      128 |
    > 129 |                   expect(res.headers['content-disposition']).toBe(
          |                                                              ^
      130 |                     expectedHeader,
      131 |                   );
      132 |                 });

      at toBe (tests/createServer.test.js:129:62)

  ● createServer › Server › POST to the "/compress" endpoint › compression type "deflate" › should respond with a correct "Content-Disposition" header

    expect(received).toBe(expected) // Object.is equality

    Expected: "attachment; filename=colonise_whoever_sleepy.jpe.deflate"
    Received: "attachment; filename=colonise_whoever_sleepy.jpe.dfl"

      127 |                   const expectedHeader = `attachment; filename=${filename}.${compressionType}`;
      128 |
    > 129 |                   expect(res.headers['content-disposition']).toBe(
          |                                                              ^
      130 |                     expectedHeader,
      131 |                   );
      132 |                 });

      at toBe (tests/createServer.test.js:129:62)
      ```

Copy link

@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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link

@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 fixing the file extension bug and implementing streams! Your solution is approved as an educational override to help you move forward.

The main area for improvement is that the server doesn't handle the required form values (gzip, deflate). Instead of changing the HTML <option> values to gz and dfl, the server should perform this mapping internally. For example, it should receive gzip from the form and know to use the .gz extension and the zlib.createGzip() stream. This makes the server more robust.

To fully meet the requirements, you'll want to update createServer.js to handle this mapping and adjust your HTML and tests accordingly. Keep up the fantastic progress!


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

Footnotes

  1. Rate AI review example

const zlib = require('node:zlib');
const { IncomingForm } = require('formidable');

const SUPPORTED_COMPRESSION_TYPES = ['gz', 'dfl', 'br'];

Choose a reason for hiding this comment

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

The task requirements state that the form options for compression type should be gzip, deflate, and br. This array should be updated to match those required values, like ['gzip', 'deflate', 'br'].

Comment on lines +37 to +41
const streams = {
gz: () => zlib.createGzip(),
dfl: () => zlib.createDeflate(),
br: () => zlib.createBrotliCompress(),
};

Choose a reason for hiding this comment

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

To align with the task requirements, the keys in this streams object should be gzip, deflate, and br. The server should expect these values from the form and map them to the correct zlib stream.

}

const compressStream = createCompressionStream(compressionType);
const encodedFilename = encodeFilename(`${filename}.${compressionType}`);

Choose a reason for hiding this comment

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

Appending compressionType directly will cause an issue once you update the form values as required. For example, if compressionType is "gzip", the filename will become filename.gzip instead of the required filename.gz. You need to create a mapping to convert the compression type (gzip, deflate) to the correct file extension (.gz, .dfl).

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