formstream 1.5.2 → 1.5.3
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 +41 -1
- package/lib/formstream.js +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,12 @@ fs.stat(filepath, function (err, stat) {
|
|
|
92
92
|
|
|
93
93
|
## API Doc
|
|
94
94
|
|
|
95
|
+
Field names and filenames use percent encoding for carriage returns (`%0D`),
|
|
96
|
+
line feeds (`%0A`), and double quotes (`%22`) in multipart headers.
|
|
97
|
+
Other characters and field contents remain unchanged.
|
|
98
|
+
The `field()`, `buffer()`, and `stream()` methods throw a `TypeError` synchronously
|
|
99
|
+
if a supplied MIME type contains a carriage return or line feed.
|
|
100
|
+
|
|
95
101
|
### formstream([options])
|
|
96
102
|
|
|
97
103
|
Create a form instance.
|
|
@@ -104,7 +110,7 @@ Create a form instance.
|
|
|
104
110
|
|
|
105
111
|
Form - form instance
|
|
106
112
|
|
|
107
|
-
### FormStream#field(name, value)
|
|
113
|
+
### FormStream#field(name, value[, mimeType])
|
|
108
114
|
|
|
109
115
|
Add a normal field to the form.
|
|
110
116
|
|
|
@@ -112,6 +118,7 @@ Add a normal field to the form.
|
|
|
112
118
|
|
|
113
119
|
- **name** String - Name of field
|
|
114
120
|
- **value** String - Value of field
|
|
121
|
+
- ***mimeType*** String - Optional. Content-Type of the field
|
|
115
122
|
|
|
116
123
|
#### Returns
|
|
117
124
|
|
|
@@ -200,6 +207,39 @@ Emitted when the stream has received no more 'data' events will happen.
|
|
|
200
207
|
|
|
201
208
|
See [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_end) for more.
|
|
202
209
|
|
|
210
|
+
## Releasing
|
|
211
|
+
|
|
212
|
+
Maintainers prepare releases through a pull request that updates the version in
|
|
213
|
+
`package.json` and describes the changes in `CHANGELOG.md`. To update the version
|
|
214
|
+
without creating a commit or tag, run `npm version patch --no-git-tag-version`
|
|
215
|
+
(or use `minor`, `major`, or an explicit version).
|
|
216
|
+
|
|
217
|
+
After the PR merges into `master`, `release.yml` compares the package versions
|
|
218
|
+
before and after the push. It publishes only when the version changes. The
|
|
219
|
+
workflow skips versions already on npm, runs the project checks, and publishes
|
|
220
|
+
with npm trusted publishing and provenance. Stable versions use the `latest`
|
|
221
|
+
dist-tag; prerelease versions use `next`.
|
|
222
|
+
|
|
223
|
+
After npm publishing succeeds, the workflow creates a GitHub release with a
|
|
224
|
+
`v<version>` tag at the commit that triggered the workflow and automatically
|
|
225
|
+
generated release notes. Prerelease versions are marked as GitHub prereleases.
|
|
226
|
+
To retry a failed release, rerun the failed workflow in GitHub Actions. If the
|
|
227
|
+
version is already on npm, the workflow still creates the missing GitHub release.
|
|
228
|
+
Existing GitHub releases remain unchanged.
|
|
229
|
+
|
|
230
|
+
Configure the `formstream` package's trusted publisher on npm with these values:
|
|
231
|
+
|
|
232
|
+
- Provider: GitHub Actions
|
|
233
|
+
- Organization: `node-modules`
|
|
234
|
+
- Repository: `formstream`
|
|
235
|
+
- Workflow filename: `release.yml`
|
|
236
|
+
- Environment: leave empty
|
|
237
|
+
- Allow direct publishing with `npm publish`
|
|
238
|
+
|
|
239
|
+
The workflow uses OIDC and does not require an `NPM_TOKEN` or `GIT_TOKEN` secret.
|
|
240
|
+
See the [npm trusted publishing documentation](https://docs.npmjs.com/trusted-publishers/)
|
|
241
|
+
for package configuration instructions.
|
|
242
|
+
|
|
203
243
|
## License
|
|
204
244
|
|
|
205
245
|
[MIT](LICENSE)
|
package/lib/formstream.js
CHANGED
|
@@ -161,14 +161,14 @@ FormStream.prototype.stream = function (name, stream, filename, mimeType, size)
|
|
|
161
161
|
mimeType = mime.getType(filename);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
var leading = this._leading({ name: name, filename: filename }, mimeType);
|
|
165
|
+
|
|
164
166
|
stream.once('error', this.emit.bind(this, 'error'));
|
|
165
167
|
// if form stream destroy, also destroy the source stream
|
|
166
168
|
this.once('destroy', function () {
|
|
167
169
|
destroy(stream);
|
|
168
170
|
});
|
|
169
171
|
|
|
170
|
-
var leading = this._leading({ name: name, filename: filename }, mimeType);
|
|
171
|
-
|
|
172
172
|
var ps = parseStream().pause();
|
|
173
173
|
stream.pipe(ps);
|
|
174
174
|
|
|
@@ -226,12 +226,18 @@ FormStream.prototype._leading = function (disposition, type) {
|
|
|
226
226
|
|
|
227
227
|
if (disposition) {
|
|
228
228
|
for (var k in disposition) {
|
|
229
|
-
|
|
229
|
+
// Escape multipart names and filenames as in HTML form submissions.
|
|
230
|
+
var value = String(disposition[k]).replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/"/g, '%22');
|
|
231
|
+
dispositions.push(k + '="' + value + '"');
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
leading.push('Content-Disposition: form-data; ' + dispositions.join('; '));
|
|
234
236
|
if (type) {
|
|
237
|
+
type = String(type);
|
|
238
|
+
if (/[\r\n]/.test(type)) {
|
|
239
|
+
throw new TypeError('MIME type must not contain CR or LF');
|
|
240
|
+
}
|
|
235
241
|
leading.push('Content-Type: ' + type);
|
|
236
242
|
}
|
|
237
243
|
|