{"id":19506319,"url":"https://github.com/thenorthmemory/multipart","last_synced_at":"2025-08-11T17:43:18.858Z","repository":{"id":64583108,"uuid":"576789651","full_name":"TheNorthMemory/multipart","owner":"TheNorthMemory","description":"Simple and lite of the multipart/form-data implementation.","archived":false,"fork":false,"pushed_at":"2022-12-13T14:24:28.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-16T11:02:23.407Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheNorthMemory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-11T01:23:18.000Z","updated_at":"2022-12-11T01:24:47.000Z","dependencies_parsed_at":"2023-01-28T12:45:44.896Z","dependency_job_id":null,"html_url":"https://github.com/TheNorthMemory/multipart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNorthMemory%2Fmultipart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNorthMemory%2Fmultipart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNorthMemory%2Fmultipart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNorthMemory%2Fmultipart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheNorthMemory","download_url":"https://codeload.github.com/TheNorthMemory/multipart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240754364,"owners_count":19852189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T22:36:39.471Z","updated_at":"2025-02-25T22:16:43.084Z","avatar_url":"https://github.com/TheNorthMemory.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multipart\n\nSimple and lite of the `multipart/form-data` implementation. Split from `wechatpay-axios-plugin` project for general usages.\n\n[![release](https://img.shields.io/npm/v/@thenorthmemory/multipart)](https://github.com/TheNorthMemory/multipart/releases)\n[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/@thenorthmemory/multipart?label=snyk.io)](https://snyk.io/advisor/npm-package/@thenorthmemory/multipart)\n[![types](https://img.shields.io/badge/types-included-blue)](https://www.npmjs.com/package/@thenorthmemory/multipart)\n[![requirement](https://img.shields.io/node/v/@thenorthmemory/multipart)](https://www.npmjs.com/package/@thenorthmemory/multipart)\n[![downloads](https://img.shields.io/npm/dm/@thenorthmemory/multipart)](https://www.npmjs.com/package/@thenorthmemory/multipart)\n[![license](https://img.shields.io/npm/l/@thenorthmemory/multipart)](https://www.npmjs.com/package/@thenorthmemory/multipart)\n\n## Usage\n\n`npm i @thenorthmemory/multipart`\n\n```js\nimport Multipart from '@thenorthmemory/multipart';\n\n// buffer style(Synchronous)\n(new Multipart())\n  .append('a', 1)\n  .append('b', '2')\n  .append('c', Buffer.from('31'))\n  .append('d', JSON.stringify({}), 'any.json')\n  .append('e', require('fs').readFileSync('/path/your/file.jpg'), 'file.jpg')\n  .getBuffer();\n\n// stream style(Asynchronous)\n(new Multipart())\n  .append('f', require('fs').createReadStream('/path/your/file2.jpg'), 'file2.jpg')\n  .pipe(require('fs').createWriteStream('./file3.jpg'));\n```\n\n## API\n\n- [Multipart](#multipart)\n  - [Usage](#usage)\n  - [API](#api)\n    - [new Multipart()](#new-multipart)\n    - [multipart.mimeTypes](#multipartmimetypes)\n    - [multipart.boundary](#multipartboundary)\n    - [multipart.data](#multipartdata)\n    - [multipart.indices](#multipartindices)\n    - [multipart.getBuffer() ⇒ \u003ccode\u003eBuffer\u003c/code\u003e](#multipartgetbuffer--buffer)\n    - [multipart.getHeaders() ⇒ \u003ccode\u003eobject.\u0026lt;string, string\u0026gt;\u003c/code\u003e](#multipartgetheaders--objectstring-string)\n    - [multipart.appendMimeTypes(things) ⇒ \u003ccode\u003ethis\u003c/code\u003e](#multipartappendmimetypesthings--this)\n    - [multipart.append(name, value, [filename]) ⇒ \u003ccode\u003ethis\u003c/code\u003e](#multipartappendname-value-filename--this)\n    - [multipart.formed(name, value, [filename]) ⇒ \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e](#multipartformedname-value-filename--arraybufferreadstream)\n    - [multipart.set(name, value, [filename]) ⇒ \u003ccode\u003ethis\u003c/code\u003e](#multipartsetname-value-filename--this)\n    - [multipart.delete(name) ⇒ \u003ccode\u003ethis\u003c/code\u003e](#multipartdeletename--this)\n    - [multipart.get(name) ⇒ \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e \\| \u003ccode\u003eundefined\u003c/code\u003e](#multipartgetname--buffer--readstream--undefined)\n    - [multipart.getAll(name) ⇒ \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e](#multipartgetallname--arraybufferreadstream)\n    - [multipart.has(name) ⇒ \u003ccode\u003eboolean\u003c/code\u003e](#multiparthasname--boolean)\n    - [multipart.entries() ⇒ \u003ccode\u003eIterator.\u0026lt;Array.\u0026lt;EntryTuple.\u0026lt;(string\\|undefined), (Buffer\\|ReadStream)\u0026gt;\u0026gt;\u0026gt;\u003c/code\u003e](#multipartentries--iteratorarrayentrytuplestringundefined-bufferreadstream)\n    - [multipart.keys() ⇒ \u003ccode\u003eIterator.\u0026lt;(string\\|undefined)\u0026gt;\u003c/code\u003e](#multipartkeys--iteratorstringundefined)\n    - [multipart.values() ⇒ \u003ccode\u003eIterator.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e](#multipartvalues--iteratorbufferreadstream)\n    - [multipart.toString() ⇒ \u003ccode\u003estring\u003c/code\u003e](#multiparttostring--string)\n    - [multipart.flowing([end]) ⇒ \u003ccode\u003ePromise.\u0026lt;this\u0026gt;\u003c/code\u003e](#multipartflowingend--promisethis)\n    - [multipart.pipe(destination, [options]) ⇒ \u003ccode\u003estream.Writable\u003c/code\u003e](#multipartpipedestination-options--streamwritable)\n  - [License](#license)\n\n\n### new Multipart()\nCreate a `multipart/form-data` buffer container for the media(image/video) file uploading.\n\n\n### multipart.mimeTypes\n**Kind**: instance property of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Access**: protected  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| mimeTypes | \u003ccode\u003eobject.\u0026lt;string, string\u0026gt;\u003c/code\u003e | Built-in mime-type mapping |\n\n\n### multipart.boundary\n**Kind**: instance property of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Read only**: true  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| boundary | \u003ccode\u003eBuffer\u003c/code\u003e | The boundary buffer. |\n\n\n### multipart.data\n**Kind**: instance property of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Access**: protected  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| data | \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e | The Multipart's instance data storage |\n\n\n### multipart.indices\n**Kind**: instance property of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Access**: protected  \n**Properties**\n\n| Name | Type | Description |\n| --- | --- | --- |\n| indices | \u003ccode\u003eArray.\u0026lt;IndexTuple.\u0026lt;(string\\|undefined), number\u0026gt;\u0026gt;\u003c/code\u003e | The entities' value indices whose were in [data](#Multipart+data) |\n\n\n### multipart.getBuffer() ⇒ \u003ccode\u003eBuffer\u003c/code\u003e\nTo retrieve the [Miltipart#data](Miltipart#data) buffer\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eBuffer\u003c/code\u003e - - The payload buffer  \n\n### multipart.getHeaders() ⇒ \u003ccode\u003eobject.\u0026lt;string, string\u0026gt;\u003c/code\u003e\nTo retrieve the `Content-Type` multipart/form-data header\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eobject.\u0026lt;string, string\u0026gt;\u003c/code\u003e - - The `Content-Type` header With [boundary](#Multipart+boundary)  \n\n### multipart.appendMimeTypes(things) ⇒ \u003ccode\u003ethis\u003c/code\u003e\nAppend a customized [Multipart#mimeType](Multipart#mimeType)\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003ethis\u003c/code\u003e - - The `Multipart` class instance self  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| things | \u003ccode\u003eobject.\u0026lt;string, string\u0026gt;\u003c/code\u003e | The mime-type |\n\n**Example**  \n```js\n.appendMimeTypes({p12: 'application/x-pkcs12'})\n.appendMimeTypes({txt: 'text/plain'})\n```\n\n### multipart.append(name, value, [filename]) ⇒ \u003ccode\u003ethis\u003c/code\u003e\nAppend data wrapped by [boundary](#Multipart+boundary)\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003ethis\u003c/code\u003e - - The `Multipart` class instance self  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n| value | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e | The value |\n| [filename] | \u003ccode\u003estring\u003c/code\u003e | Optional filename, when provided, then append the `Content-Type` after of the `Content-Disposition` |\n\n\n### multipart.formed(name, value, [filename]) ⇒ \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e\nFormed a named value, a filename reported to the server, when a Buffer or FileStream is passed as the second parameter.\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e - - The part of data  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n| value | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e | The value |\n| [filename] | \u003ccode\u003estring\u003c/code\u003e | Optional filename, when provided, then append the `Content-Type` after of the `Content-Disposition` |\n\n\n### multipart.set(name, value, [filename]) ⇒ \u003ccode\u003ethis\u003c/code\u003e\nSets a new value for an existing key inside a [data](#Multipart+data) instance, or adds the key/value if it does not already exist.\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003ethis\u003c/code\u003e - - The Multipart instance  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n| value | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e | The value |\n| [filename] | \u003ccode\u003estring\u003c/code\u003e | Optional filename, when provided, then append the `Content-Type` after of the `Content-Disposition` |\n\n\n### multipart.delete(name) ⇒ \u003ccode\u003ethis\u003c/code\u003e\nDeletes a key and its value(s) from a [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003ethis\u003c/code\u003e - - The Multipart instance  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n\n\n### multipart.get(name) ⇒ \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e \\| \u003ccode\u003eundefined\u003c/code\u003e\nReturns the first value associated with a given key from within a [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eBuffer\u003c/code\u003e \\| \u003ccode\u003eReadStream\u003c/code\u003e \\| \u003ccode\u003eundefined\u003c/code\u003e - value - The value, undefined means none named key exists  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n\n\n### multipart.getAll(name) ⇒ \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e\nReturns all values associated with a given key from within a [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eArray.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e - value(s) - The value(s)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n\n\n### multipart.has(name) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nReturns a boolean stating whether a [data](#Multipart+data) instance contains a certain key.\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eboolean\u003c/code\u003e - - True for contains  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | \u003ccode\u003estring\u003c/code\u003e | The field name |\n\n\n### multipart.entries() ⇒ \u003ccode\u003eIterator.\u0026lt;Array.\u0026lt;EntryTuple.\u0026lt;(string\\|undefined), (Buffer\\|ReadStream)\u0026gt;\u0026gt;\u0026gt;\u003c/code\u003e\nTo go through all key/value pairs contained in this [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eIterator.\u0026lt;Array.\u0026lt;EntryTuple.\u0026lt;(string\\|undefined), (Buffer\\|ReadStream)\u0026gt;\u0026gt;\u0026gt;\u003c/code\u003e - - An Array Iterator key/value pairs.  \n\n### multipart.keys() ⇒ \u003ccode\u003eIterator.\u0026lt;(string\\|undefined)\u0026gt;\u003c/code\u003e\nTo go through all keys contained in [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eIterator.\u0026lt;(string\\|undefined)\u0026gt;\u003c/code\u003e - - An Array Iterator key pairs.  \n\n### multipart.values() ⇒ \u003ccode\u003eIterator.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e\nTo go through all values contained in [data](#Multipart+data) instance\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003eIterator.\u0026lt;(Buffer\\|ReadStream)\u0026gt;\u003c/code\u003e - - An Array Iterator value pairs.  \n\n\n### multipart.toString() ⇒ \u003ccode\u003estring\u003c/code\u003e\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - - FormData string  \n\n### multipart.flowing([end]) ⇒ \u003ccode\u003ePromise.\u0026lt;this\u0026gt;\u003c/code\u003e\nPushing [data](#Multipart+data) into the readable BufferList\n\n**Kind**: instance method of [\u003ccode\u003eMultipart\u003c/code\u003e](#Multipart)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;this\u0026gt;\u003c/code\u003e - - The Multipart instance  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| [end] | \u003ccode\u003eboolean\u003c/code\u003e | \u003ccode\u003etrue\u003c/code\u003e | End the writer when the reader ends. Default: `true`. Available {@since v0.8.0} |\n\n\n### multipart.pipe(destination, [options]) ⇒ \u003ccode\u003estream.Writable\u003c/code\u003e\nAttaches a Writable stream to the [Multipart](#Multipart) instance\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenorthmemory%2Fmultipart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenorthmemory%2Fmultipart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenorthmemory%2Fmultipart/lists"}