Permalink
Browse files

update parted to 0.8

  • Loading branch information...
1 parent 666b3c4 commit e3d82c99cfb05b364c188530a18c3beaac2604b5 @nrstott committed Nov 14, 2011
Showing with 44 additions and 4 deletions.
  1. +2 −1 .npmignore
  2. +12 −2 lib/middleware.js
  3. +1 −1 package.json
  4. +29 −0 test/middleware.test.js
View
@@ -1,4 +1,5 @@
*.sublime-*
forEachableStream.txt
npm-debug.log
-
+hello-world.dat
+hello-world.txt
View
@@ -3,7 +3,8 @@ var Q = require('promised-io/lib/promise'),
fs = require('fs'),
path = require('path'),
ForEachStream = require('./forEachStream'),
- util = require('./util');
+ util = require('./util'),
+ EventEmitter = require('events').EventEmitter;
function join(forEachable) {
var body = '',
@@ -122,8 +123,17 @@ exports.Parted = function(nextApp, opts) {
return function(req) {
var deferred = Q.defer()
- , oldBody = req.body;
+ , oldBody = req.body
+ , emitter;
+
+ if (oldBody === undefined) {
+ return nextApp(req);
+ }
+
+ emitter = new ForEachStream(oldBody);
+ req.on = emitter.on.bind(emitter);
+
req.pipe = function(stream) {
Q.when(oldBody.forEach(function(chunk) {
stream.write(chunk);
View
@@ -18,7 +18,7 @@
"deflate": ">=1.0.3",
"underscore": ">=0.0.0",
"node-uuid": ">=1.2.0",
- "parted": "=0.0.7",
+ "parted": "=0.0.8",
"q": "=0.7.2"
},
"devDependencies": {
View
@@ -207,6 +207,35 @@ exports["test parted json"] = function(beforeExit) {
});
};
+exports["test parted form"] = function(beforeExit) {
+ var request = null
+ , parted = new bogart.middleware.Parted(function(req) { request = req; return {}; })
+ , body = {}
+ , bodyDefer = require('q').defer();
+
+ body.forEach = function(callback) {
+ callback('hello=one&hello=two');
+
+ return bodyDefer.promise;
+ };
+
+ response = parted({
+ method: 'POST',
+ env: {},
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
+ body: body
+ });
+
+ bodyDefer.resolve();
+
+ beforeExit(function() {
+ assert.isNotNull(request);
+ assert.ok(!!request.body);
+ assert.ok(!!request.body.hello);
+ assert.equal(2, request.body.hello.length);
+ });
+};
+
exports["test parted multipart"] = function(beforeExit) {
var request = null
, parted = new bogart.middleware.Parted(function(req) { request = req; return {}; });

0 comments on commit e3d82c9

Please sign in to comment.