-
-
Notifications
You must be signed in to change notification settings - Fork 37
multipart.js
Simple and lite of multipart/form-data
implementation, most similar to form-data
.
Kind: global class
Since: v0.7.0
-
Multipart
- new Multipart()
- .mimeTypes
.dashDash- .boundary
.EMPTY.CRLF- .data
- .indices
-
.getBuffer() ⇒
Buffer
-
.getHeaders() ⇒
object.<string, string>
-
.appendMimeTypes(things) ⇒
this
-
.append(name, value, [filename]) ⇒
this
-
.formed(name, value, [filename]) ⇒
Array.<(Buffer|ReadStream)>
-
.set(name, value, [filename]) ⇒
this
-
.delete(name) ⇒
this
-
.get(name) ⇒
Buffer
|ReadStream
|undefined
-
.getAll(name) ⇒
Array.<(Buffer|ReadStream)>
-
.has(name) ⇒
boolean
-
.entries() ⇒
Iterator.<Array.<EntryTuple.<(string|undefined), (Buffer|ReadStream)>>>
-
.keys() ⇒
Iterator.<(string|undefined)>
-
.values() ⇒
Iterator.<(Buffer|ReadStream)>
-
.toJSON() ⇒
object.<string, string>
|null
-
.toString() ⇒
string
-
.flowing([end]) ⇒
Promise.<this>
-
.pipe(destination, [options]) ⇒
stream.Writable
-
.IndexTuple :
array
-
.EntryTuple :
array
Create a multipart/form-data
buffer container for the media(image/video) file uploading.
Example
// buffer style(Synchronous)
(new Multipart())
.append('a', 1)
.append('b', '2')
.append('c', Buffer.from('31'))
.append('d', JSON.stringify({}), 'any.json')
.append('e', require('fs').readFileSync('/path/your/file.jpg'), 'file.jpg')
.getBuffer();
// stream style(Asynchronous)
(new Multipart())
.append('f', require('fs').createReadStream('/path/your/file2.jpg'), 'file2.jpg')
.pipe(require('fs').createWriteStream('./file3.jpg'));
Kind: instance property of Multipart
Access: protected
Properties
Name | Type | Description |
---|---|---|
mimeTypes | object.<string, string> |
Built-in mime-type mapping |
Deprecated
Kind: instance property of Multipart
Read only: true
Properties
Name | Type | Description |
---|---|---|
dashDash | Buffer |
Double dash buffer |
Kind: instance property of Multipart
Read only: true
Properties
Name | Type | Description |
---|---|---|
boundary | Buffer |
The boundary buffer. |
Deprecated
Kind: instance property of Multipart
Read only: true
Properties
Name | Type | Description |
---|---|---|
EMPTY | Buffer |
An empty buffer |
Deprecated
Kind: instance property of Multipart
Read only: true
Properties
Name | Type | Description |
---|---|---|
CRLF | Buffer |
The CRLF characters buffer |
Kind: instance property of Multipart
Access: protected
Properties
Name | Type | Description |
---|---|---|
data | Array.<(Buffer|ReadStream)> |
The Multipart's instance data storage |
Kind: instance property of Multipart
Access: protected
Properties
Name | Type | Description |
---|---|---|
indices | Array.<IndexTuple.<(string|undefined), number>> |
The entities' value indices whose were in data |
To retrieve the Miltipart#data buffer
Kind: instance method of Multipart
Returns: Buffer
- - The payload buffer
To retrieve the Content-Type
multipart/form-data header
Kind: instance method of Multipart
Returns: object.<string, string>
- - The Content-Type
header With boundary
Append a customized Multipart#mimeType
Kind: instance method of Multipart
Returns: this
- - The Multipart
class instance self
Param | Type | Description |
---|---|---|
things | object.<string, string> |
The mime-type |
Example
.appendMimeTypes({p12: 'application/x-pkcs12'})
.appendMimeTypes({txt: 'text/plain'})
Append data wrapped by boundary
Kind: instance method of Multipart
Returns: this
- - The Multipart
class instance self
Param | Type | Description |
---|---|---|
name | string |
The field name |
value |
string | Buffer | ReadStream
|
The value |
[filename] | string |
Optional filename, when provided, then append the Content-Type after of the Content-Disposition
|
Formed a named value, a filename reported to the server, when a Buffer or FileStream is passed as the second parameter.
Kind: instance method of Multipart
Returns: Array.<(Buffer|ReadStream)>
- - The part of data
Param | Type | Description |
---|---|---|
name | string |
The field name |
value |
string | Buffer | ReadStream
|
The value |
[filename] | string |
Optional filename, when provided, then append the Content-Type after of the Content-Disposition
|
Sets a new value for an existing key inside a data instance, or adds the key/value if it does not already exist.
Kind: instance method of Multipart
Returns: this
- - The Multipart instance
Param | Type | Description |
---|---|---|
name | string |
The field name |
value |
string | Buffer | ReadStream
|
The value |
[filename] | string |
Optional filename, when provided, then append the Content-Type after of the Content-Disposition
|
Deletes a key and its value(s) from a data instance
Kind: instance method of Multipart
Returns: this
- - The Multipart instance
Param | Type | Description |
---|---|---|
name | string |
The field name |
Returns the first value associated with a given key from within a data instance
Kind: instance method of Multipart
Returns: Buffer
| ReadStream
| undefined
- value - The value, undefined means none named key exists
Param | Type | Description |
---|---|---|
name | string |
The field name |
Returns all values associated with a given key from within a data instance
Kind: instance method of Multipart
Returns: Array.<(Buffer|ReadStream)>
- value(s) - The value(s)
Param | Type | Description |
---|---|---|
name | string |
The field name |
Returns a boolean stating whether a data instance contains a certain key.
Kind: instance method of Multipart
Returns: boolean
- - True for contains
Param | Type | Description |
---|---|---|
name | string |
The field name |
To go through all key/value pairs contained in this data instance
Kind: instance method of Multipart
Returns: Iterator.<Array.<EntryTuple.<(string|undefined), (Buffer|ReadStream)>>>
- - An Array Iterator key/value pairs.
To go through all keys contained in data instance
Kind: instance method of Multipart
Returns: Iterator.<(string|undefined)>
- - An Array Iterator key pairs.
To go through all values contained in data instance
Kind: instance method of Multipart
Returns: Iterator.<(Buffer|ReadStream)>
- - An Array Iterator value pairs.
The WeChatPay APIv3' specific, the meta
JSON
Kind: instance method of Multipart
Returns: object.<string, string>
| null
- - The meta{filename,sha1}
information.
Kind: instance method of Multipart
Returns: string
- - FormData string
Pushing data into the readable BufferList
Kind: instance method of Multipart
Returns: Promise.<this>
- - The Multipart instance
Param | Type | Default | Description |
---|---|---|---|
[end] | boolean |
true |
End the writer when the reader ends. Default: true . Available {@since v0.8.0} |
Attaches a Writable stream to the Multipart instance
Kind: instance method of Multipart
Returns: stream.Writable
- - The destination, allowing for a chain of pipes
Param | Type | Default | Description |
---|---|---|---|
destination | stream.Writable |
The destination for writing data | |
[options] | object |
Pipe options | |
[options.end] | boolean |
true |
End the writer when the reader ends. Default: true. |
- two element array
Kind: instance typedef of Multipart
Access: protected
Properties
Type | Description |
---|---|
0 |
string |
1 |
number |
- two element array
Kind: instance typedef of Multipart
Access: protected
Properties
Type | Description |
---|---|
0 |
string |
1 |
Buffer |