formstream 0.0.7 → 1.1.1
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 +28 -0
- package/README.md +20 -20
- package/lib/formstream.js +33 -19
- package/package.json +23 -18
- package/.npmignore +0 -7
- package/LICENSE.txt +0 -21
- package/index.js +0 -1
package/History.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
|
|
2
|
+
1.1.1 / 2021-04-28
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
**fixes**
|
|
6
|
+
* [[`c96ba5b`](http://github.com/node-modules/formstream/commit/c96ba5bace0e96bf39770769e43d9de4271971d8)] - fix: upgrade mime to fix wrong mime type (#19) (shaozj <<shaozj@users.noreply.github.com>>)
|
|
7
|
+
|
|
8
|
+
**others**
|
|
9
|
+
* [[`21918e5`](http://github.com/node-modules/formstream/commit/21918e5fc37a4cea5aae82659d39587f099e805b)] - chore: upgrade devDeps express to latest version (#15) (fengmk2 <<fengmk2@gmail.com>>)
|
|
10
|
+
|
|
11
|
+
1.1.0 / 2016-12-19
|
|
12
|
+
==================
|
|
13
|
+
|
|
14
|
+
* deps: upgrade mime to latest version (#9)
|
|
15
|
+
|
|
16
|
+
1.0.0 / 2014-11-04
|
|
17
|
+
==================
|
|
18
|
+
|
|
19
|
+
* fix(field): support stream.field(String, Number)
|
|
20
|
+
* chore: fix links
|
|
21
|
+
* chore: use npm scripts instead of Makefile
|
|
22
|
+
* fix test case on node@0.8
|
|
23
|
+
|
|
24
|
+
0.0.8 / 2014-01-17
|
|
25
|
+
==================
|
|
26
|
+
|
|
27
|
+
* destroy source stream when formstream destroy()
|
|
28
|
+
* add more test cases
|
|
29
|
+
|
|
2
30
|
0.0.7 / 2013-07-25
|
|
3
31
|
==================
|
|
4
32
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
![
|
|
1
|
+
# formstream
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![build status][travis-image]][travis-url]
|
|
5
|
+
[![Test coverage][coveralls-image]][coveralls-url]
|
|
6
|
+
[![David deps][david-image]][david-url]
|
|
7
|
+
[![npm download][download-image]][download-url]
|
|
8
|
+
|
|
9
|
+
[npm-image]: https://img.shields.io/npm/v/formstream.svg?style=flat-square
|
|
10
|
+
[npm-url]: https://npmjs.org/package/formstream
|
|
11
|
+
[travis-image]: https://img.shields.io/travis/node-modules/formstream.svg?style=flat-square
|
|
12
|
+
[travis-url]: https://travis-ci.org/node-modules/formstream
|
|
13
|
+
[coveralls-image]: https://img.shields.io/coveralls/node-modules/formstream.svg?style=flat-square
|
|
14
|
+
[coveralls-url]: https://coveralls.io/r/node-modules/formstream?branch=master
|
|
15
|
+
[david-image]: https://img.shields.io/david/node-modules/formstream.svg?style=flat-square
|
|
16
|
+
[david-url]: https://david-dm.org/node-modules/formstream
|
|
17
|
+
[download-image]: https://img.shields.io/npm/dm/formstream.svg?style=flat-square
|
|
18
|
+
[download-url]: https://npmjs.org/package/formstream
|
|
5
19
|
|
|
6
20
|
A [multipart/form-data](http://tools.ietf.org/html/rfc2388) encoded stream, helper for file upload.
|
|
7
21
|
|
|
@@ -166,26 +180,12 @@ Emitted when the stream has received no more 'data' events will happen.
|
|
|
166
180
|
|
|
167
181
|
See [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_end) for more.
|
|
168
182
|
|
|
169
|
-
## Authors
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
$ git summary
|
|
173
|
-
|
|
174
|
-
project : formstream
|
|
175
|
-
repo age : 10 months
|
|
176
|
-
active : 15 days
|
|
177
|
-
commits : 28
|
|
178
|
-
files : 14
|
|
179
|
-
authors :
|
|
180
|
-
21 fengmk2 75.0%
|
|
181
|
-
7 XiNGRZ 25.0%
|
|
182
|
-
```
|
|
183
|
-
|
|
184
183
|
## License
|
|
185
184
|
|
|
186
185
|
(The MIT License)
|
|
187
186
|
|
|
188
|
-
Copyright (c) 2012 -
|
|
187
|
+
Copyright (c) 2012 - 2014 fengmk2 <fengmk2@gmail.com>
|
|
188
|
+
Copyright(c) node-modules and other contributors.
|
|
189
189
|
|
|
190
190
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
191
191
|
a copy of this software and associated documentation files (the
|
package/lib/formstream.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* formstream - lib/formstream.js
|
|
3
|
-
* Copyright(c) 2012 - 2013 fengmk2 <fengmk2@gmail.com>
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
6
2
|
* Data format:
|
|
7
3
|
*
|
|
8
4
|
|
|
@@ -25,18 +21,15 @@ Content-Type: image/png\r\n
|
|
|
25
21
|
*
|
|
26
22
|
*/
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
'use strict';
|
|
29
25
|
|
|
30
|
-
/**
|
|
31
|
-
* Module dependencies.
|
|
32
|
-
*/
|
|
33
|
-
require('buffer-concat');
|
|
34
26
|
var Stream = require('stream');
|
|
35
27
|
var parseStream = require('pause-stream');
|
|
36
28
|
var util = require('util');
|
|
37
29
|
var mime = require('mime');
|
|
38
30
|
var path = require('path');
|
|
39
31
|
var fs = require('fs');
|
|
32
|
+
var destroy = require('destroy');
|
|
40
33
|
|
|
41
34
|
var PADDING = '--';
|
|
42
35
|
var NEW_LINE = '\r\n';
|
|
@@ -117,7 +110,7 @@ FormStream.prototype.headers = function (options) {
|
|
|
117
110
|
};
|
|
118
111
|
|
|
119
112
|
FormStream.prototype.file = function (name, filepath, filename, filesize) {
|
|
120
|
-
var mimeType = mime.
|
|
113
|
+
var mimeType = mime.getType(filepath);
|
|
121
114
|
|
|
122
115
|
if (typeof filename === 'number' && !filesize) {
|
|
123
116
|
filesize = filename;
|
|
@@ -131,20 +124,37 @@ FormStream.prototype.file = function (name, filepath, filename, filesize) {
|
|
|
131
124
|
return this.stream(name, stream, filename, mimeType, filesize);
|
|
132
125
|
};
|
|
133
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Add a form field
|
|
129
|
+
* @param {String} name field name
|
|
130
|
+
* @param {String|Buffer} value field value
|
|
131
|
+
* @return {this}
|
|
132
|
+
*/
|
|
134
133
|
FormStream.prototype.field = function (name, value) {
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (!Buffer.isBuffer(value)) {
|
|
135
|
+
// field(String, Number)
|
|
136
|
+
// https://github.com/qiniu/nodejs-sdk/issues/123
|
|
137
|
+
if (typeof value === 'number') {
|
|
138
|
+
value = String(value);
|
|
139
|
+
}
|
|
140
|
+
value = new Buffer(value);
|
|
141
|
+
}
|
|
142
|
+
return this.buffer(name, value);
|
|
137
143
|
};
|
|
138
144
|
|
|
139
145
|
FormStream.prototype.stream = function (name, stream, filename, mimeType, size) {
|
|
140
146
|
if (typeof mimeType === 'number' && !size) {
|
|
141
147
|
size = mimeType;
|
|
142
|
-
mimeType = mime.
|
|
148
|
+
mimeType = mime.getType(filename);
|
|
143
149
|
} else if (!mimeType) {
|
|
144
|
-
mimeType = mime.
|
|
150
|
+
mimeType = mime.getType(filename);
|
|
145
151
|
}
|
|
146
152
|
|
|
147
|
-
stream.
|
|
153
|
+
stream.once('error', this.emit.bind(this, 'error'));
|
|
154
|
+
// if form stream destroy, also destroy the source stream
|
|
155
|
+
this.once('destroy', function () {
|
|
156
|
+
destroy(stream);
|
|
157
|
+
});
|
|
148
158
|
|
|
149
159
|
var leading = this._leading({ name: name, filename: filename }, mimeType);
|
|
150
160
|
|
|
@@ -170,12 +180,12 @@ FormStream.prototype.stream = function (name, stream, filename, mimeType, size)
|
|
|
170
180
|
|
|
171
181
|
FormStream.prototype.buffer = function (name, buffer, filename, mimeType) {
|
|
172
182
|
if (filename && !mimeType) {
|
|
173
|
-
mimeType = mime.
|
|
183
|
+
mimeType = mime.getType(filename);
|
|
174
184
|
}
|
|
175
185
|
|
|
176
|
-
var disposition = { name: name }
|
|
186
|
+
var disposition = { name: name };
|
|
177
187
|
if (filename) {
|
|
178
|
-
disposition.filename = filename
|
|
188
|
+
disposition.filename = filename;
|
|
179
189
|
}
|
|
180
190
|
|
|
181
191
|
var leading = this._leading(disposition, mimeType);
|
|
@@ -277,3 +287,7 @@ FormStream.prototype.resume = function () {
|
|
|
277
287
|
|
|
278
288
|
return this;
|
|
279
289
|
};
|
|
290
|
+
|
|
291
|
+
FormStream.prototype.close = FormStream.prototype.destroy = function () {
|
|
292
|
+
this.emit('destroy');
|
|
293
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formstream",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A multipart/form-data encoded stream, helper for file upload.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/formstream.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
6
9
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"
|
|
9
|
-
"travis
|
|
10
|
+
"test": "mocha -R spec -t 5000 -r should test/*.test.js",
|
|
11
|
+
"test-cov": "istanbul cover node_modules/.bin/_mocha -- -t 5000 -r should test/*.test.js",
|
|
12
|
+
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- -t 5000 -r should test/*.test.js",
|
|
13
|
+
"jshint": "jshint .",
|
|
14
|
+
"autod": "autod -w --prefix '^'"
|
|
10
15
|
},
|
|
11
16
|
"repository": {
|
|
12
17
|
"type": "git",
|
|
13
|
-
"url": "git://github.com/
|
|
18
|
+
"url": "git://github.com/node-modules/formstream.git"
|
|
14
19
|
},
|
|
15
20
|
"keywords": [
|
|
16
21
|
"form",
|
|
@@ -22,20 +27,20 @@
|
|
|
22
27
|
"request"
|
|
23
28
|
],
|
|
24
29
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"pause-stream": "
|
|
30
|
+
"destroy": "^1.0.4",
|
|
31
|
+
"mime": "^2.5.2",
|
|
32
|
+
"pause-stream": "~0.0.11"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
35
|
+
"autod": "*",
|
|
36
|
+
"connect-multiparty": "1",
|
|
37
|
+
"express": "^4.16.4",
|
|
38
|
+
"istanbul": "*",
|
|
39
|
+
"mocha": "3",
|
|
40
|
+
"pedding": "1",
|
|
41
|
+
"should": "4",
|
|
42
|
+
"urllib": "2"
|
|
38
43
|
},
|
|
39
|
-
"author": "fengmk2 <fengmk2@gmail.com> (
|
|
44
|
+
"author": "fengmk2 <fengmk2@gmail.com> (https://fengmk2.com)",
|
|
40
45
|
"license": "MIT"
|
|
41
46
|
}
|
package/.npmignore
DELETED
package/LICENSE.txt
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
This software is licensed under the MIT License.
|
|
2
|
-
|
|
3
|
-
Copyright (C) 2012 - 2013 by fengmk2 <fengmk2@gmail.com>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./lib/formstream');
|