Giter VIP home page Giter VIP logo

http-data-parser's Introduction

Build Status

Description

An extremely fast Node.js module for parsing form data and primarily file uploads.

Requirements

Node.js 6.14.3 or higher is required.

Installation

npm i @slaviczavik/http-data-parser

Example

const HttpDataParser = require('@slaviczavik/http-data-parser')

// A boundary must be extracted from 'content-type' request header.
const boundary = '--------------------------034172598905589540726558'
const parser = HttpDataParser(boundary)

parser.on('header', function (data, isLast) {
  // Save headers somewhere...

  if (isLast) {
    // Here you may prepare for handling body data,
    // like create a writable stream and so on.
  }
})

parser.on('data', function (data) {
  // Save body content somewhere...
})

parser.on('part', function () {
  // We reached the end of one body part.
  // Here we can concate body content together.
})

parser.on('end', function () {
  // We reached the end of whole body.
  // No other data will come.
})

req.on('data', function (data) {
  parser.write(data)
})

req.on('end', function () {
  parser.end()
})

API

Constructor

HttpDataParser(boundary)

Name Required Type Description Default
boundary true string none

Methods

The parser is a Node.js Writable Stream, so you can use the write and the end methods, or just only the pipe method.

write(buffer)

Parameter Required Type Description
buffer true buffer Buffer from request body.

end()

Call this method when there is no more data to be consumed from the stream.

Events

header(data, isLast)

Emitted every time when a parser find a header part.

Property Type Description
data buffer -
isLast boolean Signals if it is a last header part.

data(data)

Emitted every time when a parser find a content data.

Property Type Description
data buffer -

part()

Emitted every time when a parser reach the end of one body part.

end()

Emitted when a parser reached the end of request body.

http-data-parser's People

Contributors

slaviczavik avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Forkers

farcry2-online

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.