Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ exports.Parse = function(multipartBodyBuffer,boundary){
// { filename: 'A.txt', type: 'text/plain', data: <Buffer 41 41 41 41 42 42 42 42> }
var obj = function(str){
var k = str.split('=');
var a = k[0].trim();
var b = JSON.parse(k[1].trim());
var a = k[0]?.trim() || '';
var b = JSON.parse(k[1]?.trim() || '{}');
var o = {};
Object.defineProperty( o , a ,
{ value: b, writable: true, enumerable: true, configurable: true })
return o;
}
var header = part.header.split(';');
var header = part.header.split(';');
var file = obj(header[2]);
var contentType = part.info.split(':')[1].trim();
var contentType = part.info.split(':')[1]?.trim() || '';
Object.defineProperty( file , 'type' ,
{ value: contentType, writable: true, enumerable: true, configurable: true })
Object.defineProperty( file , 'data' ,
Expand Down Expand Up @@ -64,7 +64,7 @@ exports.Parse = function(multipartBodyBuffer,boundary){
lastline='';
}else
if((1 == state) && newLineDetected){
header = lastline;
header = lastline + ';;';
state=2;
lastline='';
}else
Expand All @@ -85,7 +85,7 @@ exports.Parse = function(multipartBodyBuffer,boundary){
var part = buffer.slice(0,j-1);
var p = { header : header , info : info , part : part };
allParts.push(process(p));
buffer = []; lastline=''; state=5; header=''; info='';
buffer = []; lastline=''; state=5; header=';;'; info='';
}else{
buffer.push(oneByte);
}
Expand Down Expand Up @@ -135,4 +135,3 @@ exports.DemoData = function(){
return (new Buffer(body,'utf-8'));
// returns a Buffered payload, so the it will be treated as a binary content.
};