Git Product home page Git Product logo

multipart-js's Introduction

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();

multipart-js's People

Contributors

isaacs avatar mrjjwright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

multipart-js's Issues

Online Demo

Hey, nice job with the repo. if possible, i'd really appreciate an online demo of the functionality. I think it'd also help you get more users as well, who aren't interesting in downloading anything before they know what they're downloading.

multipart has no method parser?

Hi,

var multipart = require('multipart');
...
var parser = multipart.parser();

I got TypeError: Object has no method 'parser'.

what's wrong with it?

ReferenceError: writer is not defined

Hi,

I'm seeing your sample at http://www.componentix.com/blog/13 but when I try to run it I receive this error:

ReferenceError: writer is not defined
at Object. (/Users/emerson.leite/.node_libraries/.npm/multipart/0.0.0/package/lib/write.js:2:1)
at Module._compile (module:423:23)
at Module._loadScriptSync (module:433:8)
at Module.loadSync (module:306:10)
at loadModule (module:251:12)
at require (module:374:12)
at Object. (/Users/emerson.leite/.node_libraries/.npm/multipart/0.0.0/package/lib/multipart.js:4:13)
at Module._compile (module:423:23)
at Module._loadScriptSync (module:433:8)
at Module.loadSync (module:306:10)

Cheers

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.