Skip to content

Commit

Permalink
ADDED: README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-M1M3 committed Jul 6, 2022
1 parent e74f779 commit 54d0ff6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
examples/
yarn.lock
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

# Parter

A Promise based version of busboy


## Documentation

Parter uses busboy under the hood. In fact, parter is written to make busboy promise based.
To install parter, run

```bash
yarn add parter
```
or,

```bash
npm install parter
```

Now, you can import it and instantiate it,

```javascript
import parter from 'parter';

async function requestHandler(req, res){
// other things
const body = await parter(req);
// other things
}
```

Notice, we pass in `req` as the first argument. The `req` we pass in must be an instance of
`IncomingMessage` from node `http` module or it can be an instance of `Request` constructor.

You can also pass in an abject as a second parameter. This object is to configure parter.
As, parter uses `busboy`, this is the same configuration object you would pass
in busboy. But, you can, of course pass additional properties.

```javascript
options.errorOnMoreFields = Boolean
options.errorOnMoreFiles = Boolean
options.errorOnMoreParts = Boolean
options.errorOnLargerFileSize = Boolean
```
- `errorOnMoreFields`

Whether to reject if `fieldsLimit` is emitted from busboy

- `errorOnMoreFiles`

Whether to reject if `filesLimit` is emitted from busboy

- `errorOnMoreParts`

Whether to reject if `partsLimit` is emitted from busboy

- `errorOnLargerFileSize`

Whether to reject if `limit` is emitted from busboy.
## Authors

- [@mr-m1m3](https://www.github.com/mr-m1m3)
5 changes: 1 addition & 4 deletions lib/parter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ export default async function parter(req, options) {
}

if (!options.headers) { // if options object doesn't contain headers

options.headers = req.headers; // set option.headers to req.headers

}

const bb = busboy(options); // instantiate busboy

if (req instanceof Request) { // if req is an instance of Request

// pipe request body, a readable stream to busboy instance which is an writable stream.
//NOTE: body of Request instance is a readable stream and in nodejs readable stream `pipeTo` is not available.
//Rather, we use `pipe()`;
req.body.pipe(bb);


} else if (req instanceof IncomingMessage) { // if req is an instance of node IncomingMessage

// nodejs IncomingMessage is a stream.
Expand Down

0 comments on commit 54d0ff6

Please sign in to comment.