Skip to content

Commit

Permalink
Use text-encoding npm package instead of integrated text-encoding dep. (
Browse files Browse the repository at this point in the history
#50)

* replace encodings

* use external TextDecoder as polyfill

* add information to changelog

* move dependencies closer to devDependencies

* add benchmark

* add missing \r\n\r\n to each part

* create utf8 and latin1 specific benchmarks

* also encode the content of the parts

* extracted createMultipartBufferForFormBench

* rename createMultipartBufferForEncodingBench to createMultipartBufferForEncodingBench
fix typo in Changelog

* add unit test

* fix linting issues

* Add explicit charset

* latin1 is the same as iso8859-1 but is like the unit test i wrote

* use Map instead of Object,bind streamsearch onInfo directly

* fix linting

* fix benchmarks

* revert unnecessary change for this PR

* Minor cleanup

Co-authored-by: Igor Savin <iselwin@gmail.com>
  • Loading branch information
Uzlopak and kibertoad authored Dec 4, 2021
1 parent 158b6f8 commit 640f5ab
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 1,795 deletions.
31 changes: 16 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Changelog

Major changes since the last busboy release (0.3.1):

# 1.0.0 - TBD, 2021

* TypeScript types are now included in the package itself (#13)
* Non-deprecated Buffer creation is used (#8, #10)
* Error on non-number limit rather than ignoring (#7)
* Dicer is now part of the busboy itself and not an external dependency (#14)
* Tests were converted to Mocha (#11, #12, #22, #23)
* Add isPartAFile-option, to make the file-detection configurable (#53)
* Empty Parts will not hang the process (#55)
* FileStreams also provide the property `bytesRead` (#51)
* add and expose headerSize limit (#64)
# Changelog

Major changes since the last busboy release (0.3.1):

# 1.0.0 - TBD, 2021

* TypeScript types are now included in the package itself (#13)
* Non-deprecated Buffer creation is used (#8, #10)
* Error on non-number limit rather than ignoring (#7)
* Dicer is now part of the busboy itself and not an external dependency (#14)
* Tests were converted to Mocha (#11, #12, #22, #23)
* Using the native TextDecoder and the package 'text-decoding' for fallback if nodejs does not support the requested encoding (#50)
* Add isPartAFile-option, to make the file-detection configurable (#53)
* Empty Parts will not hang the process (#55)
* FileStreams also provide the property `bytesRead` (#51)
* add and expose headerSize limit (#64)
30 changes: 30 additions & 0 deletions bench/busboy-form-bench-latin1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Busboy = require('busboy');
const { createMultipartBufferForEncodingBench } = require("./createMultipartBufferForEncodingBench");

for (var i = 0, il = 10000; i < il; i++) { // eslint-disable-line no-var
const boundary = '-----------------------------168072824752491622650073',
busboy = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
buffer = createMultipartBufferForEncodingBench(boundary, 100, 'iso-8859-1'),
mb = buffer.length / 1048576;

let processedData = 0;
busboy.on('file', (field, file, filename, encoding, mimetype) => {
file.resume()
})

busboy.on('error', function (err) {
})
busboy.on('finish', function () {
})

const start = +new Date();
const result = busboy.write(buffer, () => { });
busboy.end();
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);
console.log(mbPerSec + ' mb/sec');
}
30 changes: 30 additions & 0 deletions bench/busboy-form-bench-utf8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Busboy = require('busboy');
const { createMultipartBufferForEncodingBench } = require("./createMultipartBufferForEncodingBench");

for (var i = 0, il = 10000; i < il; i++) { // eslint-disable-line no-var
const boundary = '-----------------------------168072824752491622650073',
busboy = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
buffer = createMultipartBufferForEncodingBench(boundary, 100, 'utf-8'),
mb = buffer.length / 1048576;

let processedData = 0;
busboy.on('file', (field, file, filename, encoding, mimetype) => {
file.resume()
})

busboy.on('error', function (err) {
})
busboy.on('finish', function () {
})

const start = +new Date();
const result = busboy.write(buffer, () => { });
busboy.end();
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);
console.log(mbPerSec + ' mb/sec');
}
21 changes: 21 additions & 0 deletions bench/createMultipartBufferForEncodingBench.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions bench/fastify-busboy-form-bench-latin1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Busboy = require('../lib/main');
const { createMultipartBufferForEncodingBench } = require("./createMultipartBufferForEncodingBench");

for (var i = 0, il = 10000; i < il; i++) { // eslint-disable-line no-var
const boundary = '-----------------------------168072824752491622650073',
busboy = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
buffer = createMultipartBufferForEncodingBench(boundary, 100, 'iso-8859-1'),
mb = buffer.length / 1048576;

busboy.on('file', (field, file, filename, encoding, mimetype) => {
file.resume()
})

busboy.on('error', function (err) {
})
busboy.on('finish', function () {
})

const start = +new Date();
busboy.write(buffer, () => { });
busboy.end();
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);
console.log(mbPerSec + ' mb/sec');
}
29 changes: 29 additions & 0 deletions bench/fastify-busboy-form-bench-utf8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Busboy = require('../lib/main');
const { createMultipartBufferForEncodingBench } = require("./createMultipartBufferForEncodingBench");

for (var i = 0, il = 10000; i < il; i++) { // eslint-disable-line no-var
const boundary = '-----------------------------168072824752491622650073',
busboy = new Busboy({
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary
}
}),
buffer = createMultipartBufferForEncodingBench(boundary, 100, 'utf-8'),
mb = buffer.length / 1048576;

busboy.on('file', (field, file, filename, encoding, mimetype) => {
file.resume()
})

busboy.on('error', function (err) {
})
busboy.on('finish', function () {
})

const start = +new Date();
busboy.write(buffer, () => { });
busboy.end();
const duration = +new Date - start;
const mbPerSec = (mb / (duration / 1000)).toFixed(2);
console.log(mbPerSec + ' mb/sec');
}
Loading

0 comments on commit 640f5ab

Please sign in to comment.