-
Notifications
You must be signed in to change notification settings - Fork 304
feat: file compression #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [20.x] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm install | ||
| - run: npm test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <base href="/" /> | ||
| <title>Document</title> | ||
| </head> | ||
| <body> | ||
| <h1>Compress your files!</h1> | ||
| <form | ||
| id="compressionForm" | ||
| action="/compress" | ||
| method="POST" | ||
| enctype="multipart/form-data" | ||
| > | ||
| <div class="form__item"> | ||
| <label for="file">File:</label> | ||
| <input type="file" id="file" name="file" /> | ||
| </div> | ||
|
|
||
| <div class="form__item"> | ||
| <label for="compressionType">Compression Type:</label> | ||
| <select name="compressionType" id="compressionType"> | ||
| <option value="" selected disabled> | ||
| Select type | ||
| </option> | ||
| <option value="gzip">GZIP</option> | ||
| <option value="deflate">Deflate</option> | ||
| <option value="brotli">Brotli</option> | ||
| <option value="der">der</option> | ||
| </select> | ||
| </div> | ||
| <button type="submit">Submit</button> | ||
| </form> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,15 @@ function stringToStream(str) { | |
| const compressionTypes = { | ||
| gzip: { | ||
| decompress: util.promisify(zlib.gunzip), | ||
| extension: 'gz', | ||
| }, | ||
| deflate: { | ||
| decompress: util.promisify(zlib.inflate), | ||
| extension: 'dfl', | ||
| }, | ||
| br: { | ||
| decompress: util.promisify(zlib.brotliDecompress), | ||
| extension: 'br', | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -96,7 +99,7 @@ describe('createServer', () => { | |
| }); | ||
|
|
||
| Object.entries(compressionTypes).forEach( | ||
| ([compressionType, { decompress }]) => { | ||
| ([compressionType, { decompress, extension }]) => { | ||
| describe(`compression type "${compressionType}"`, () => { | ||
| it('should respond with 200 status code', () => { | ||
| expect.assertions(1); | ||
|
|
@@ -124,7 +127,7 @@ describe('createServer', () => { | |
| headers: formData.getHeaders(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }) | ||
| .then((res) => { | ||
| const expectedHeader = `attachment; filename=${filename}.${compressionType}`; | ||
| const expectedHeader = `attachment; filename=${filename}.${extension}`; | ||
|
|
||
| expect(res.headers['content-disposition']).toBe( | ||
| expectedHeader, | ||
|
|
||
There was a problem hiding this comment.
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
realPathto the response. Consider usingfs.createReadStream()and piping its output to theresobject.