Need help with multipart-js?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

isaacs
121 Stars 32 Forks 26 Commits 3 Opened issues

Services available

!
?

Need anything else?

Contributors list

# 156
C++
node
code-co...
Electro...
16 commits
# 250,381
C++
C
Shell
sqlciph...
8 commits

multipart-js

A JavaScript library for parsing and writing multipart messages.

Current State

Pre-pre-alpha. Almost nothing is here, and what is here is likely completely broken.

If you are asking about this, you probably ought to check out Felix's node-formidable library.

Usage

If you're familiar with sax-js, then most of this should be pretty straightforward. Attach event handlers, call functions, close it when you're done. Please keep fingers and dangling clothing away from the state machine.

var multipart = require("multipart");

// parsing var parser = multipart.parser();

// in all event handlers, "this" is the parser, and "this.part" is the // part that's currently being dealt with. parser.onpartbegin = function (part) { doSomething(part) }; parser.ondata = function (chunk) { doSomethingElse(chunk) }; parser.onend = function () { closeItUp() };

// now start feeding the message through it. // you can do this all in one go, if you like, or one byte at a time, // or anything in between. parser.boundary = "foo"; var chunk; while ( chunk = upstreamThing.getNextChunk() ) { parser.write(chunk); } parser.close();

// writing var writer = multipart.writer();

// attach event handlers for the things we care about. writer.ondata = function (chunk) { doSomething(chunk) }; writer.onend = function () { closeItUp() };

// now trigger the events to fire by feeding files through it. writer.boundary = "foo"; writer.partBegin({ "content-type" : "text/plain", filename : "foo.txt" }); var chunk; while ( chunk = getChunkOfFile() ) { writer.write(chunk); } writer.partEnd(); writer.close();

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.