Skip to content

Commit

Permalink
Code quality (#525)
Browse files Browse the repository at this point in the history
* prefer template literals

* avoid self = this

* prefer template literals

* split default options into separate file for clarity
  • Loading branch information
GrosSacASac committed Dec 1, 2019
1 parent db3f376 commit 18d10d1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 132 deletions.
11 changes: 11 additions & 0 deletions lib/default_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const defaultOptions = {
maxFields: 1000,
maxFieldsSize: 20 * 1024 * 1024,
maxFileSize: 200 * 1024 * 1024,
keepExtensions: false,
encoding: 'utf-8',
hash: false,
multiples: false,
};

exports.defaultOptions = defaultOptions;
24 changes: 11 additions & 13 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,32 @@ File.prototype.toJSON = function() {
};

File.prototype.toString = function () {
return "File:" + this.name + ", Path:" + this.path;
return `File: ${this.name}, Path: ${this.path}`;
};

File.prototype.write = function(buffer, cb) {
var self = this;
if (self.hash) {
self.hash.update(buffer);
if (this.hash) {
this.hash.update(buffer);
}

if (this._writeStream.closed) {
return cb();
}

this._writeStream.write(buffer, function() {
self.lastModifiedDate = new Date();
self.size += buffer.length;
self.emit('progress', self.size);
this._writeStream.write(buffer, () => {
this.lastModifiedDate = new Date();
this.size += buffer.length;
this.emit('progress', this.size);
cb();
});
};

File.prototype.end = function(cb) {
var self = this;
if (self.hash) {
self.hash = self.hash.digest('hex');
if (this.hash) {
this.hash = this.hash.digest('hex');
}
this._writeStream.end(function() {
self.emit('end');
this._writeStream.end(() => {
this.emit('end');
cb();
});
};

0 comments on commit 18d10d1

Please sign in to comment.