formstream 1.1.1 → 1.3.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/README.md +0 -6
- package/lib/formstream.js +4 -4
- package/package.json +14 -11
- package/types/formstream.d.ts +72 -0
- package/History.md +0 -73
package/README.md
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
# formstream
|
|
2
2
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
|
-
[![build status][travis-image]][travis-url]
|
|
5
4
|
[![Test coverage][coveralls-image]][coveralls-url]
|
|
6
|
-
[![David deps][david-image]][david-url]
|
|
7
5
|
[![npm download][download-image]][download-url]
|
|
8
6
|
|
|
9
7
|
[npm-image]: https://img.shields.io/npm/v/formstream.svg?style=flat-square
|
|
10
8
|
[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
9
|
[coveralls-image]: https://img.shields.io/coveralls/node-modules/formstream.svg?style=flat-square
|
|
14
10
|
[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
11
|
[download-image]: https://img.shields.io/npm/dm/formstream.svg?style=flat-square
|
|
18
12
|
[download-url]: https://npmjs.org/package/formstream
|
|
19
13
|
|
package/lib/formstream.js
CHANGED
|
@@ -33,7 +33,7 @@ var destroy = require('destroy');
|
|
|
33
33
|
|
|
34
34
|
var PADDING = '--';
|
|
35
35
|
var NEW_LINE = '\r\n';
|
|
36
|
-
var NEW_LINE_BUFFER =
|
|
36
|
+
var NEW_LINE_BUFFER = Buffer.from(NEW_LINE);
|
|
37
37
|
|
|
38
38
|
function FormStream() {
|
|
39
39
|
if (!(this instanceof FormStream)) {
|
|
@@ -45,7 +45,7 @@ function FormStream() {
|
|
|
45
45
|
this._boundary = this._generateBoundary();
|
|
46
46
|
this._streams = [];
|
|
47
47
|
this._buffers = [];
|
|
48
|
-
this._endData =
|
|
48
|
+
this._endData = Buffer.from(PADDING + this._boundary + PADDING + NEW_LINE);
|
|
49
49
|
this._contentLength = 0;
|
|
50
50
|
this._isAllStreamSizeKnown = true;
|
|
51
51
|
this._knownStreamSize = 0;
|
|
@@ -137,7 +137,7 @@ FormStream.prototype.field = function (name, value) {
|
|
|
137
137
|
if (typeof value === 'number') {
|
|
138
138
|
value = String(value);
|
|
139
139
|
}
|
|
140
|
-
value =
|
|
140
|
+
value = Buffer.from(value);
|
|
141
141
|
}
|
|
142
142
|
return this.buffer(name, value);
|
|
143
143
|
};
|
|
@@ -222,7 +222,7 @@ FormStream.prototype._leading = function (disposition, type) {
|
|
|
222
222
|
leading.push('');
|
|
223
223
|
leading.push('');
|
|
224
224
|
|
|
225
|
-
return
|
|
225
|
+
return Buffer.from(leading.join(NEW_LINE));
|
|
226
226
|
};
|
|
227
227
|
|
|
228
228
|
FormStream.prototype._emitBuffers = function () {
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formstream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A multipart/form-data encoded stream, helper for file upload.",
|
|
5
5
|
"main": "lib/formstream.js",
|
|
6
|
+
"types": "types/formstream.d.ts",
|
|
6
7
|
"files": [
|
|
7
|
-
"lib"
|
|
8
|
+
"lib",
|
|
9
|
+
"types/formstream.d.ts"
|
|
8
10
|
],
|
|
9
11
|
"scripts": {
|
|
10
|
-
"test": "
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"test": "egg-bin test",
|
|
13
|
+
"cov": "egg-bin cov",
|
|
14
|
+
"ci": "npm run lint && npm run tsd && npm run cov",
|
|
15
|
+
"lint": "jshint .",
|
|
16
|
+
"tsd": "tsd"
|
|
15
17
|
},
|
|
16
18
|
"repository": {
|
|
17
19
|
"type": "git",
|
|
@@ -32,15 +34,16 @@
|
|
|
32
34
|
"pause-stream": "~0.0.11"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"
|
|
37
|
+
"@types/node": "^20.4.3",
|
|
36
38
|
"connect-multiparty": "1",
|
|
39
|
+
"egg-bin": "^5.6.1",
|
|
37
40
|
"express": "^4.16.4",
|
|
38
|
-
"
|
|
39
|
-
"mocha": "3",
|
|
41
|
+
"jshint": "^2.13.6",
|
|
40
42
|
"pedding": "1",
|
|
41
43
|
"should": "4",
|
|
44
|
+
"tsd": "^0.28.1",
|
|
42
45
|
"urllib": "2"
|
|
43
46
|
},
|
|
44
|
-
"author": "fengmk2 <fengmk2@gmail.com> (https://
|
|
47
|
+
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
|
|
45
48
|
"license": "MIT"
|
|
46
49
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Readable, Stream } from 'stream'
|
|
2
|
+
|
|
3
|
+
declare class FormStream extends Stream {
|
|
4
|
+
/**
|
|
5
|
+
* Add a normal field to the form.
|
|
6
|
+
*
|
|
7
|
+
* @param name Name of field
|
|
8
|
+
* @param value Value of field
|
|
9
|
+
*/
|
|
10
|
+
field(name: string, value: string): this
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add a local file to be uploaded to the form.
|
|
14
|
+
*
|
|
15
|
+
* @param name Name of file field
|
|
16
|
+
* @param filepath Local path of the file to be uploaded
|
|
17
|
+
* @param filename Name of the file (will be the base name of filepath if empty)
|
|
18
|
+
* @param filesize Size of the file (will not generate Content-Length header if not specified)
|
|
19
|
+
*/
|
|
20
|
+
file(
|
|
21
|
+
name: string,
|
|
22
|
+
filepath: string,
|
|
23
|
+
filename?: string,
|
|
24
|
+
filesize?: number,
|
|
25
|
+
): this
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Add a buffer as a file to upload.
|
|
29
|
+
*
|
|
30
|
+
* @param name Name of field
|
|
31
|
+
* @param buffer The buffer to be uploaded
|
|
32
|
+
* @param filename The file name that tells the remote server
|
|
33
|
+
* @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
|
|
34
|
+
*/
|
|
35
|
+
buffer(
|
|
36
|
+
name: string,
|
|
37
|
+
buffer: Buffer,
|
|
38
|
+
filename: string,
|
|
39
|
+
contentType?: string,
|
|
40
|
+
): this
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
|
|
44
|
+
*
|
|
45
|
+
* @param name Name of field
|
|
46
|
+
* @param stream A readable stream to be piped
|
|
47
|
+
* @param filename The file name that tells the remote server
|
|
48
|
+
* @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
|
|
49
|
+
* @param size Size of the stream (will not generate Content-Length header if not specified)
|
|
50
|
+
*/
|
|
51
|
+
stream(
|
|
52
|
+
name: string,
|
|
53
|
+
stream: Readable,
|
|
54
|
+
filename: string,
|
|
55
|
+
contentType?: string,
|
|
56
|
+
size?: number,
|
|
57
|
+
): this
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get headers for the request.
|
|
61
|
+
*
|
|
62
|
+
* @param additionalHeaders Additional headers
|
|
63
|
+
*/
|
|
64
|
+
headers(additionalHeaders?: Record<string, any>): Record<string, any>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare const formStream: {
|
|
68
|
+
new (): FormStream
|
|
69
|
+
(): FormStream
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export = formStream
|
package/History.md
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
|
|
30
|
-
0.0.7 / 2013-07-25
|
|
31
|
-
==================
|
|
32
|
-
|
|
33
|
-
* feature: always try to infer `Content-Length` (@xingrz)
|
|
34
|
-
* doc improve
|
|
35
|
-
|
|
36
|
-
0.0.6 / 2013-07-15
|
|
37
|
-
==================
|
|
38
|
-
|
|
39
|
-
* added test cases for chaining call (@xingrz)
|
|
40
|
-
* improved docs (@xingrz)
|
|
41
|
-
* added chaining support (@xingrz)
|
|
42
|
-
* api doc
|
|
43
|
-
* fixed test causes
|
|
44
|
-
* update dependencies version
|
|
45
|
-
|
|
46
|
-
0.0.5 / 2012-11-06
|
|
47
|
-
==================
|
|
48
|
-
|
|
49
|
-
* fixed stream error not catch bug
|
|
50
|
-
|
|
51
|
-
0.0.4 / 2012-11-06
|
|
52
|
-
==================
|
|
53
|
-
|
|
54
|
-
* fixed #2 support form.buffer()
|
|
55
|
-
* add doc for setTotalStreamSize()
|
|
56
|
-
|
|
57
|
-
0.0.3 / 2012-11-06
|
|
58
|
-
==================
|
|
59
|
-
|
|
60
|
-
* support content-length use form.setTotalStreamSize(size)
|
|
61
|
-
* update readme
|
|
62
|
-
|
|
63
|
-
0.0.2 / 2012-10-11
|
|
64
|
-
==================
|
|
65
|
-
|
|
66
|
-
* use buffer-concat support node < 0.8
|
|
67
|
-
|
|
68
|
-
0.0.1 / 2012-10-11
|
|
69
|
-
==================
|
|
70
|
-
|
|
71
|
-
* support multi streams.
|
|
72
|
-
* add one stream support now.
|
|
73
|
-
* Initial commit
|