formidable
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -5,3 +5,4 @@ if (global.GENTLY) require = GENTLY.hijack(require); | ||
WriteStream = require('fs').WriteStream, | ||
EventEmitter = require('events').EventEmitter; | ||
EventEmitter = require('events').EventEmitter, | ||
crypto = require('crypto'); | ||
@@ -15,6 +16,7 @@ function File(properties) { | ||
this.type = null; | ||
this.hash = null; | ||
this.lastModifiedDate = null; | ||
this._writeStream = null; | ||
for (var key in properties) { | ||
@@ -24,2 +26,6 @@ this[key] = properties[key]; | ||
if(typeof this.hash === 'string') { | ||
this.hash = crypto.createHash(properties.hash); | ||
} | ||
this._backwardsCompatibility(); | ||
@@ -51,2 +57,5 @@ } | ||
this._writeStream.write(buffer, function() { | ||
if(self.hash) { | ||
self.hash.update(buffer); | ||
} | ||
self.lastModifiedDate = new Date(); | ||
@@ -62,2 +71,5 @@ self.size += buffer.length; | ||
this._writeStream.end(function() { | ||
if(self.hash) { | ||
self.hash = self.hash.digest('hex'); | ||
} | ||
self.emit('end'); | ||
@@ -64,0 +76,0 @@ cb(); |
@@ -13,15 +13,18 @@ if (global.GENTLY) require = GENTLY.hijack(require); | ||
function IncomingForm() { | ||
function IncomingForm(opts) { | ||
if (!(this instanceof IncomingForm)) return new IncomingForm; | ||
EventEmitter.call(this); | ||
opts=opts||{}; | ||
this.error = null; | ||
this.ended = false; | ||
this.maxFieldsSize = 2 * 1024 * 1024; | ||
this.keepExtensions = false; | ||
this.uploadDir = IncomingForm.UPLOAD_DIR; | ||
this.encoding = 'utf-8'; | ||
this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024; | ||
this.keepExtensions = opts.keepExtensions || false; | ||
this.uploadDir = opts.uploadDir || IncomingForm.UPLOAD_DIR; | ||
this.encoding = opts.encoding || 'utf-8'; | ||
this.headers = null; | ||
this.type = null; | ||
this.hash = false; | ||
@@ -192,2 +195,3 @@ this.bytesReceived = null; | ||
type: part.mime, | ||
hash: self.hash | ||
}); | ||
@@ -194,0 +198,0 @@ |
{ | ||
"name": "formidable", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"dependencies": {}, | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -202,2 +202,6 @@ # Formidable | ||
__incomingForm.hash = false__ | ||
If you want checksums calculated for incoming files, set this to either `'sha1'` or `'md5'`. | ||
__incomingForm.bytesReceived__ | ||
@@ -294,2 +298,6 @@ | ||
__file.hash = null__ | ||
If hash calculation was set, you can read the hex digest out of this var. | ||
## License | ||
@@ -296,0 +304,0 @@ |
@@ -15,2 +15,3 @@ var common = require('../common'); | ||
form.uploadDir = TEST_TMP; | ||
form.hash = 'sha1'; | ||
form.parse(req); | ||
@@ -45,2 +46,3 @@ | ||
assert.ok(uploads['shortest_video.flv'].progress.length > 3); | ||
assert.equal(uploads['shortest_video.flv'].file.hash, 'd6a17616c7143d1b1438ceeef6836d1a09186b3a'); | ||
assert.equal(uploads['shortest_video.flv'].progress.slice(-1), uploads['shortest_video.flv'].file.length); | ||
@@ -50,2 +52,3 @@ assert.ok(uploads['shortest_video.mp4']); | ||
assert.ok(uploads['shortest_video.mp4'].progress.length > 3); | ||
assert.equal(uploads['shortest_video.mp4'].file.hash, '937dfd4db263f4887ceae19341dcc8d63bcd557f'); | ||
@@ -52,0 +55,0 @@ server.close(); |
93263
44
2463
312
22