Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-multipart-iterator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-multipart-iterator

Iterate over the parts of a multipart document

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

async-multipart-iterator

Iterate the parts of an RFC 1528 multipart (multipart/mixed, multipart/alternative, multipart/digest, multipart/parallel) document, sequentially producing a header and a body iterator for each part.

Quick example

'use strict'
const someInputFile = 'something';  // name of a multipart file to be parsed
const someOutputDir = '/tmp/something';  // name of a directory in which bodies of each of the parts will be written
const boundary = 'cd67d1a112145bdcfdce0c5839b36b53'; // the boundaries to be found in the input file

const fs = require('fs');
const {multipartIterator} = require('async-multipart-iterator');

async function main() {
    const input = fs.createReadStream(someInputFile);

    let count = 0;
    for await (let [header, bodyIterator] of multipartIterator(boundary, input)) {
        // here for each part of the document
        console.log(header)  // right now just an array of unparsed lines from the part's header
        const stream = fs.createWriteStream(`{someOutputFile}/${count++}`);
        for await (let chunk of bodyIterator) {
            await new Promise( (res,rej) => stream.write(chunk, res));
        }
        await new Promise( (res,rej) => stream.end(res));
    }
}
main().catch(console.error)

Keywords

FAQs

Package last updated on 26 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc