From 54d0ff6339e9245d3b21a1fb81f494e5d111784a Mon Sep 17 00:00:00 2001 From: Abir Sheikh Date: Wed, 6 Jul 2022 11:00:26 +0600 Subject: [PATCH] ADDED: README.md --- .gitignore | 1 - README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/parter.js | 5 +--- 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 9ca5480..167ab9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules/ -examples/ yarn.lock \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d6709c --- /dev/null +++ b/README.md @@ -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) \ No newline at end of file diff --git a/lib/parter.js b/lib/parter.js index f40ae08..6a5798e 100644 --- a/lib/parter.js +++ b/lib/parter.js @@ -31,13 +31,11 @@ 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. @@ -45,7 +43,6 @@ export default async function parter(req, options) { //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.