Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

allow multipart upload of empty file #41

Merged
merged 2 commits into from

2 participants

@jeffbski

uploading an empty file caused an exception in the multipart/file because writeStream was not previously created.

I added a failing test and then the fix which creates the stream in the constructor.

 1) multipart Parser for an empty text file upload "before each" hook:
     TypeError: Cannot call method 'end' of undefined
      at File.end (/Users/barczewskij/projects/strata/lib/multipart/file.js:48:21)
      at Part.Parser.onPart.content (/Users/barczewskij/projects/strata/lib/multipart/parser.js:380:12)
      at Part.EventEmitter.emit (events.js:93:17)
      at Part.end (/Users/barczewskij/projects/strata/lib/multipart/part.js:69:8)
jeffbski added some commits
@jeffbski jeffbski add test for multipart upload empty file 3d8eb8d
@jeffbski jeffbski allow multipart upload of empty file
Fixes the exception from the failing test

```
  1) multipart Parser for an empty text file upload "before each" hook:
     TypeError: Cannot call method 'end' of undefined
      at File.end (/Users/barczewskij/projects/strata/lib/multipart/file.js:48:21)
      at Part.Parser.onPart.content (/Users/barczewskij/projects/strata/lib/multipart/parser.js:380:12)
      at Part.EventEmitter.emit (events.js:93:17)
      at Part.end (/Users/barczewskij/projects/strata/lib/multipart/part.js:69:8)
```
37b2157
@mjackson mjackson merged commit f1f0695 into mjackson:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2013
  1. @jeffbski
  2. @jeffbski

    allow multipart upload of empty file

    jeffbski authored
    Fixes the exception from the failing test
    
    ```
      1) multipart Parser for an empty text file upload "before each" hook:
         TypeError: Cannot call method 'end' of undefined
          at File.end (/Users/barczewskij/projects/strata/lib/multipart/file.js:48:21)
          at Part.Parser.onPart.content (/Users/barczewskij/projects/strata/lib/multipart/parser.js:380:12)
          at Part.EventEmitter.emit (events.js:93:17)
          at Part.end (/Users/barczewskij/projects/strata/lib/multipart/part.js:69:8)
    ```
This page is out of date. Refresh to see the latest.
View
1  lib/multipart/file.js
@@ -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
7 test/_files/empty
@@ -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
28 test/multipart-test.js
@@ -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');
Something went wrong with that request. Please try again.