-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
replace into-stream with Readable.from #289
Conversation
Signed-off-by: Matteo Collina <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
@@ -7,7 +7,7 @@ const fp = require('fastify-plugin') | |||
const encodingNegotiator = require('@fastify/accept-negotiator') | |||
const pump = require('pump') | |||
const mimedb = require('mime-db') | |||
const intoStream = require('into-stream') | |||
const { Readable } = require('readable-stream') |
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.
Side note, should install readable-stream
once and update the package.json
dependencies.
const fsPromises = require('fs').promises | ||
const { join } = require('path') | ||
const { fetch } = require('undici') | ||
|
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.
const longStringWithEmoji = new Array(5_000) | |
.fill('0') | |
.map(() => { | |
const random = new Array(10).fill('A').join('🍃') | |
return random + '- FASTIFY COMPRESS,🍃 FASTIFY COMPRESS' | |
}) | |
.join('\n') |
const { test } = require('tap') | ||
const Fastify = require('fastify') | ||
const fastifyCompress = require('..') | ||
const fsPromises = require('fs').promises |
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.
const fsPromises = require('fs').promises |
fastify.register(async (instance, opts) => { | ||
await fastify.register(fastifyCompress) | ||
instance.get('/issue', async (req, reply) => { | ||
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') |
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.
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') |
}) | ||
|
||
fastify.get('/good', async (req, reply) => { | ||
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') |
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.
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') | |
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') |
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') | ||
|
||
return longStringWithEmoji // <--- the file content is corrupt | ||
// search for "hydra.alibaba.com" will see 2 wired question marks instead of emoji |
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.
// search for "hydra.alibaba.com" will see 2 wired question marks instead of emoji | |
// Expect response should not contain any � |
instance.get('/issue', async (req, reply) => { | ||
const longStringWithEmoji = await fsPromises.readFile(join(__dirname, './test.txt'), 'utf-8') | ||
|
||
return longStringWithEmoji // <--- the file content is corrupt |
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.
return longStringWithEmoji // <--- the file content is corrupt | |
return longStringWithEmoji |
return longStringWithEmoji // <--- the file content is ok | ||
// search for "hydra.alibaba.com" will see emoji |
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.
return longStringWithEmoji // <--- the file content is ok | |
// search for "hydra.alibaba.com" will see emoji | |
return longStringWithEmoji | |
// Expect response should not contain any � |
|
const response2 = await fetch(`${url}/good`) | ||
const body = await response.text() | ||
const body2 = await response2.text() | ||
t.equal(body, body2) |
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.
t.equal(body, body2) | |
t.equal(body, body2) | |
t.equal(body.indexOf('�'), -1) | |
t.equal(body2.indexOf('�'), -1) |
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.
Ensure number of emoji is valid
@mcollina I suggest to generate a long string instead of loading from |
Fixes #288