Skip to content

Commit f7aef85

Browse files
fix: Remove dicer dependency to libs/utils.js (#105)
* fix: Remove dicer dependecny to libs/utils.js * fix * more changes Co-authored-by: Lahiru Maramba <[email protected]>
1 parent 63a7075 commit f7aef85

16 files changed

+257
-210
lines changed

deps/dicer/lib/Dicer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const WritableStream = require('stream').Writable
24
const inherits = require('util').inherits
35

deps/dicer/lib/HeaderParser.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
'use strict'
2+
13
const EventEmitter = require('events').EventEmitter
24
const inherits = require('util').inherits
3-
const getLimit = require('../../../lib/utils').getLimit
5+
const getLimit = require('../../../lib/utils/getLimit')
46

57
const StreamSearch = require('../../streamsearch/sbmh')
68

deps/dicer/lib/PartStream.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const inherits = require('util').inherits
24
const ReadableStream = require('stream').Readable
35

deps/streamsearch/sbmh.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
/**
24
* Copyright Brian White. All rights reserved.
35
*

lib/main.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
'use strict'
2+
13
const WritableStream = require('stream').Writable
24
const { inherits } = require('util')
35
const Dicer = require('../deps/dicer/lib/Dicer')
46

57
const MultipartParser = require('./types/multipart')
68
const UrlencodedParser = require('./types/urlencoded')
7-
const parseParams = require('./utils').parseParams
9+
const parseParams = require('./utils/parseParams')
810

911
function Busboy (opts) {
1012
if (!(this instanceof Busboy)) { return new Busboy(opts) }

lib/types/multipart.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
// TODO:
24
// * support 1 nested multipart level
35
// (see second multipart example here:
@@ -10,10 +12,10 @@ const inherits = require('util').inherits
1012

1113
const Dicer = require('../../deps/dicer/lib/Dicer')
1214

13-
const parseParams = require('../utils').parseParams
14-
const decodeText = require('../utils').decodeText
15-
const basename = require('../utils').basename
16-
const getLimit = require('../utils').getLimit
15+
const parseParams = require('../utils/parseParams')
16+
const decodeText = require('../utils/decodeText')
17+
const basename = require('../utils/basename')
18+
const getLimit = require('../utils/getLimit')
1719

1820
const RE_BOUNDARY = /^boundary$/i
1921
const RE_FIELD = /^form-data$/i

lib/types/urlencoded.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const Decoder = require('../utils').Decoder
2-
const decodeText = require('../utils').decodeText
3-
const getLimit = require('../utils').getLimit
1+
'use strict'
2+
3+
const Decoder = require('../utils/Decoder')
4+
const decodeText = require('../utils/decodeText')
5+
const getLimit = require('../utils/getLimit')
46

57
const RE_CHARSET = /^charset$/i
68

lib/utils.js

-198
This file was deleted.

lib/utils/Decoder.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict'
2+
3+
const RE_PLUS = /\+/g
4+
5+
const HEX = [
6+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
10+
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12+
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
14+
]
15+
16+
function Decoder () {
17+
this.buffer = undefined
18+
}
19+
Decoder.prototype.write = function (str) {
20+
// Replace '+' with ' ' before decoding
21+
str = str.replace(RE_PLUS, ' ')
22+
let res = ''
23+
let i = 0; let p = 0; const len = str.length
24+
for (; i < len; ++i) {
25+
if (this.buffer !== undefined) {
26+
if (!HEX[str.charCodeAt(i)]) {
27+
res += '%' + this.buffer
28+
this.buffer = undefined
29+
--i // retry character
30+
} else {
31+
this.buffer += str[i]
32+
++p
33+
if (this.buffer.length === 2) {
34+
res += String.fromCharCode(parseInt(this.buffer, 16))
35+
this.buffer = undefined
36+
}
37+
}
38+
} else if (str[i] === '%') {
39+
if (i > p) {
40+
res += str.substring(p, i)
41+
p = i
42+
}
43+
this.buffer = ''
44+
++p
45+
}
46+
}
47+
if (p < len && this.buffer === undefined) { res += str.substring(p) }
48+
return res
49+
}
50+
Decoder.prototype.reset = function () {
51+
this.buffer = undefined
52+
}
53+
54+
module.exports = Decoder

lib/utils/basename.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
3+
module.exports = function basename (path) {
4+
if (typeof path !== 'string') { return '' }
5+
for (var i = path.length - 1; i >= 0; --i) { // eslint-disable-line no-var
6+
switch (path.charCodeAt(i)) {
7+
case 0x2F: // '/'
8+
case 0x5C: // '\'
9+
path = path.slice(i + 1)
10+
return (path === '..' || path === '.' ? '' : path)
11+
}
12+
}
13+
return (path === '..' || path === '.' ? '' : path)
14+
}

0 commit comments

Comments
 (0)