multipart-raw-parser-legacy
v1.0.1
Published
[![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![coverages][coverage-image]][coverage-url] [![downloads][downloads-image]][downloads-url] [![Commitizen friendly][cf-image]][cf-url] [![semantic-release][sm-image]][sm-url]
Downloads
6
Readme
Multipart Raw Parser
The multipart raw parser is a helper function to parse a multipart/whatever Content-Type from any HttpRequest response.
Installation
Install the npm module:
$ npm install multipart-raw-parser --save
Documentation
Arguments
contentType
: The response headerContent-Type
.body
: The response body as a string containing all multipart data parts.
A multipart/whatever response is composed for each content of a boundary identifier
, headers
and contents
:
--uuid:2e6eb930-a6da-43e2-850c-ce98e3bbdb16
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
...
</soap:Body>
</soap:Envelope>
--uuid:2e6eb930-a6da-43e2-850c-ce98e3bbdb16
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
sdbjkcndsjkvbdjs...
NOTE: The function will not process any form which do not contain a boundary identifier (--id:...
).
Returns
An array of objects composed of an index representing the position of the part in the body
parameters, the part value and a array of object containing parsed headers.
Example
Here is a simple way to use the library:
import fetch from 'fetch'
import { parse } from 'multipart-raw-parser'
try {
const response = await fetch('https://wh.at/raw')
const multipartDataArray = parse(response, response.headers.get('Content-Type'))
console.log(multipartDataArray)
// [...{
// index: 1,
// headers: [{
// name: 'Content-Type',
// value: 'application/octet-stream'
// }, ...],
// value: 'sdbjkcndsjkvbdjs...'
// }]
} catch (e) {
throw (e)
}
Development
To run the function locally:
npm install
npm run dev
Keep CI tests passing by running npm run test
or npm run test:watch
and npm run lint
often.
Change Log
This project adheres to Semantic Versioning.
You can find every release documented on the Releases page.
License
MIT