1.0.1 • Published 3 years ago

multipart-raw-parser-legacy v1.0.1

Weekly downloads
6
License
MIT
Repository
-
Last release
3 years ago

Multipart Raw Parser

travis npm coverages downloads Commitizen friendly semantic-release

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 header Content-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: <root.message@cxf.apache.org>

<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: <cc4451c7-9084-401b-b20d-c40331c4c43d-47984@cxf.apache.org>

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