Permalink
Browse files

Merge pull request #41 from jeffbski/0.20.0-upload-empty-file

allow multipart upload of empty file
  • Loading branch information...
2 parents 2ed7f99 + 37b2157 commit f1f0695a3b98b71e40cdedeb449e214bd06b3939 @mjackson committed Mar 20, 2013
Showing with 36 additions and 0 deletions.
  1. +1 −0 lib/multipart/file.js
  2. +7 −0 test/_files/empty
  3. +28 −0 test/multipart-test.js
View
@@ -17,6 +17,7 @@ function File(path, type, name) {
this.type = type;
this.name = name;
this.size = 0;
+ this._writeStream = fs.createWriteStream(this.path);
}
util.inherits(File, EventEmitter);
View
@@ -0,0 +1,7 @@
+--AaB03x
+Content-Type: text/plain
+Content-Disposition: attachment; name="files"; filename=empty.txt; modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
+Content-Description: an empty text file
+
+
+--AaB03x--
View
@@ -124,6 +124,34 @@ describe('multipart', function () {
});
});
+ describe('for an empty text file upload', function () {
+ parseFixture('empty');
+
+ it('correctly parses the file name', function () {
+ var file = params.files;
+ assert.ok(file);
+ assert.equal(file.name, 'empty.txt');
+ });
+
+ it('correctly parses the file content type', function () {
+ var file = params.files;
+ assert.ok(file);
+ assert.equal(file.type, 'text/plain');
+ });
+
+ it('correctly determines the file size', function () {
+ var file = params.files;
+ assert.ok(file);
+ assert.strictEqual(file.size, 0);
+ });
+
+ it("correctly parses the file's contents", function () {
+ var file = params.files;
+ assert.ok(file);
+ assert.equal(fs.readFileSync(file.path, 'utf8'), '');
+ });
+ });
+
describe('for a text file upload using IE-style filename', function () {
parseFixture('text_ie');

0 comments on commit f1f0695

Please sign in to comment.