@poppinss/multiparty 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +5 -0
- package/README.md +1 -1
- package/index.js +45 -5
- package/package.json +9 -7
package/HISTORY.md
CHANGED
package/README.md
CHANGED
|
@@ -271,5 +271,5 @@ stream uploads to disk for you.
|
|
|
271
271
|
|
|
272
272
|
[npm-version-image]: https://img.shields.io/npm/v/@poppinss/multiparty?style=for-the-badge
|
|
273
273
|
|
|
274
|
-
[gh-workflow-image]: https://img.shields.io/github/workflow/status/poppinss/multiparty/test?style=for-the-badge
|
|
274
|
+
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/multiparty/test.yml?style=for-the-badge
|
|
275
275
|
[gh-workflow-url]: https://github.com/poppinss/multiparty/actions/workflows/test.yml "Github action"
|
package/index.js
CHANGED
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
'use strict'
|
|
10
10
|
|
|
11
11
|
var createError = require('http-errors')
|
|
12
|
-
var uid = require('uid-safe')
|
|
13
12
|
var stream = require('stream');
|
|
14
13
|
var util = require('util');
|
|
15
14
|
var fs = require('fs');
|
|
16
15
|
var path = require('path');
|
|
17
16
|
var os = require('os');
|
|
18
|
-
var
|
|
17
|
+
var crypto = require('crypto');
|
|
19
18
|
var StringDecoder = require('string_decoder').StringDecoder;
|
|
20
19
|
|
|
21
20
|
var START = 0;
|
|
@@ -48,6 +47,20 @@ var NAME_PARAM_RE = /\bname=(?:"([^"]+)"|([!#$%&'*+.0-9A-Z^_`a-z|~-]+))/i
|
|
|
48
47
|
|
|
49
48
|
exports.Form = Form;
|
|
50
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Generates a URL safe random string of a given size
|
|
52
|
+
*/
|
|
53
|
+
function randomUid(size) {
|
|
54
|
+
var bits = (size + 1) * 6
|
|
55
|
+
var buffer = crypto.randomBytes(Math.ceil(bits / 8))
|
|
56
|
+
return Buffer.from(buffer)
|
|
57
|
+
.toString('base64')
|
|
58
|
+
.replace(/\+/g, '-')
|
|
59
|
+
.replace(/\//g, '_')
|
|
60
|
+
.replace(/=/g, '')
|
|
61
|
+
.slice(0, size)
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
util.inherits(Form, stream.Writable);
|
|
52
65
|
function Form(options) {
|
|
53
66
|
var opts = options || {}
|
|
@@ -672,7 +685,14 @@ function handlePart(self, partStream) {
|
|
|
672
685
|
endFlush(self);
|
|
673
686
|
});
|
|
674
687
|
emitAndReleaseHold(function() {
|
|
675
|
-
self
|
|
688
|
+
if (hasListeners(self, 'part')) {
|
|
689
|
+
self.emit('part', partStream)
|
|
690
|
+
} else {
|
|
691
|
+
partStream.on('error', function (err) {
|
|
692
|
+
self.handleError(err)
|
|
693
|
+
})
|
|
694
|
+
partStream.resume()
|
|
695
|
+
}
|
|
676
696
|
});
|
|
677
697
|
}
|
|
678
698
|
|
|
@@ -754,6 +774,26 @@ function handleField(self, fieldStream) {
|
|
|
754
774
|
});
|
|
755
775
|
}
|
|
756
776
|
|
|
777
|
+
/**
|
|
778
|
+
* Determine if emitter has listeners of a given type.
|
|
779
|
+
*
|
|
780
|
+
* The way to do this check is done three different ways in Node.js >= 0.10
|
|
781
|
+
* so this consolidates them into a minimal set using instance methods.
|
|
782
|
+
*
|
|
783
|
+
* @param {EventEmitter} emitter
|
|
784
|
+
* @param {string} type
|
|
785
|
+
* @returns {boolean}
|
|
786
|
+
* @private
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
function hasListeners (emitter, type) {
|
|
790
|
+
var count = typeof emitter.listenerCount !== 'function'
|
|
791
|
+
? emitter.listeners(type).length
|
|
792
|
+
: emitter.listenerCount(type)
|
|
793
|
+
|
|
794
|
+
return count > 0
|
|
795
|
+
}
|
|
796
|
+
|
|
757
797
|
function clearPartVars(self) {
|
|
758
798
|
self.partHeaders = {};
|
|
759
799
|
self.partName = null;
|
|
@@ -792,7 +832,7 @@ function setUpParser(self, boundary) {
|
|
|
792
832
|
|
|
793
833
|
function uploadPath(baseDir, filename) {
|
|
794
834
|
var ext = path.extname(filename).replace(FILE_EXT_RE, '$1');
|
|
795
|
-
var name =
|
|
835
|
+
var name = randomUid(18) + ext
|
|
796
836
|
return path.join(baseDir, name);
|
|
797
837
|
}
|
|
798
838
|
|
|
@@ -809,7 +849,7 @@ function parseFilename(headerValue) {
|
|
|
809
849
|
|
|
810
850
|
var filename = m[1] || m[2] || '';
|
|
811
851
|
filename = filename.replace(/%22|\\"/g, '"');
|
|
812
|
-
filename = filename.replace(/&#([
|
|
852
|
+
filename = filename.replace(/&#([0-9]{1,5});/g, function(m, code) {
|
|
813
853
|
return String.fromCharCode(code);
|
|
814
854
|
});
|
|
815
855
|
return filename.substr(filename.lastIndexOf('\\') + 1);
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/multiparty",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "multipart/form-data parser which supports streaming",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
|
8
|
+
"Felix Geisendörfer <felix@debuggable.com>"
|
|
9
|
+
],
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"keywords": [
|
|
8
12
|
"file",
|
|
@@ -12,20 +16,18 @@
|
|
|
12
16
|
"s3"
|
|
13
17
|
],
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"http-errors": "^2.0.0"
|
|
16
|
-
"safe-buffer": "5.2.1",
|
|
17
|
-
"uid-safe": "2.1.5"
|
|
19
|
+
"http-errors": "^2.0.0"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"eslint": "^8.
|
|
22
|
+
"eslint": "^8.9.0",
|
|
21
23
|
"eslint-plugin-markdown": "2.2.1",
|
|
22
24
|
"mkdirp": "^1.0.4",
|
|
23
|
-
"mocha": "^9.1
|
|
25
|
+
"mocha": "^9.2.1",
|
|
24
26
|
"nyc": "15.1.0",
|
|
25
27
|
"pend": "1.2.0",
|
|
26
28
|
"require-all": "3.0.0",
|
|
27
29
|
"rimraf": "^3.0.2",
|
|
28
|
-
"superagent": "^
|
|
30
|
+
"superagent": "^7.1.1"
|
|
29
31
|
},
|
|
30
32
|
"files": [
|
|
31
33
|
"HISTORY.md",
|