Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heapwolf/stream-body
parse a stream correctly (according to the content-type) using raw-body
https://github.com/heapwolf/stream-body
Last synced: 25 days ago
JSON representation
parse a stream correctly (according to the content-type) using raw-body
- Host: GitHub
- URL: https://github.com/heapwolf/stream-body
- Owner: heapwolf
- Created: 2016-11-27T15:48:24.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-25T14:38:00.000Z (almost 7 years ago)
- Last Synced: 2024-10-18T17:26:29.613Z (26 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SYNOPSIS
Get the complete body from a stream and parse it automatically.# MOTIVATION
A minimal wrapper around [raw-body](https://github.com/stream-utils/raw-body)
that provides you with the correct parser.# BUILD STATUS
[![Build Status](https://travis-ci.org/0x00A/stream-body.svg?branch=master)](https://travis-ci.org/0x00A/stream-body)# USAGE
This module detects the content type of the stream and parses it appropriately.
So for instance, if you request a resource with a `content-type` header which
has the value of `application/json`, the response body will be parsed as `JSON`.```js
const http = require('http')
const body = require('stream-body')const url = 'http://nodejs.org/dist/index.json'
http.get(url, res => body.parse(res, (err, data) => {
// ...`data` will be a json object.
}))
```# EXTENDING
This module exports an object that exposes all parsers. For instance, the `JSON`
parser implemintation is defined on the `parsers` member...```js
const body = require('stream-body')body.parsers['application/json'] = function (data, opts, cb) {
// `data` is the raw data object
// `opts` is any options passed in to the parse function
// `cb` is called after the stream has ended
}
```