Skip to content
Browse files

enable hash calculation again

  • Loading branch information...
1 parent c409a27 commit 3733c2c9d17837d8329094f7348f20e939ac313f @egirshov egirshov committed
Showing with 10 additions and 10 deletions.
  1. +8 −8 lib/file.js
  2. +2 −2 test/legacy/system/test-multi-video-upload.js
View
16 lib/file.js
@@ -23,6 +23,8 @@ function File(properties) {
if(typeof this.hash === 'string') {
this.hash = crypto.createHash(properties.hash);
+ } else {
+ this.hash = null;
}
}
module.exports = File;
@@ -47,12 +49,10 @@ File.prototype.toJSON = function() {
File.prototype.write = function(buffer, cb) {
var self = this;
+ if (self.hash) {
+ self.hash.update(buffer);
+ }
this._writeStream.write(buffer, function() {
- if (self.hash) {
- if (self.hash.hasOwnProperty('update')) {
- self.hash.update(buffer);
- }
- }
self.lastModifiedDate = new Date();
self.size += buffer.length;
self.emit('progress', self.size);
@@ -62,10 +62,10 @@ File.prototype.write = function(buffer, cb) {
File.prototype.end = function(cb) {
var self = this;
+ if (self.hash) {
+ self.hash = self.hash.digest('hex');
+ }
this._writeStream.end(function() {
- if(self.hash) {
- self.hash = self.hash.digest('hex');
- }
self.emit('end');
cb();
});
View
4 test/legacy/system/test-multi-video-upload.js
@@ -41,12 +41,12 @@ server.on('request', function(req, res) {
assert.ok(uploads['shortest_video.flv']);
assert.ok(uploads['shortest_video.flv'].ended);
assert.ok(uploads['shortest_video.flv'].progress.length > 3);
- assert.equal(uploads['shortest_video.flv'].file.hash, 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
+ assert.equal(uploads['shortest_video.flv'].file.hash, 'd6a17616c7143d1b1438ceeef6836d1a09186b3a');
assert.equal(uploads['shortest_video.flv'].progress.slice(-1), uploads['shortest_video.flv'].file.size);
assert.ok(uploads['shortest_video.mp4']);
assert.ok(uploads['shortest_video.mp4'].ended);
assert.ok(uploads['shortest_video.mp4'].progress.length > 3);
- assert.equal(uploads['shortest_video.mp4'].file.hash, 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
+ assert.equal(uploads['shortest_video.mp4'].file.hash, '937dfd4db263f4887ceae19341dcc8d63bcd557f');
server.close();
res.writeHead(200);

0 comments on commit 3733c2c

Please sign in to comment.
Something went wrong with that request. Please try again.