diff --git a/lib/fdfs.js b/lib/fdfs.js index 7c7f9c2..a7087db 100644 --- a/lib/fdfs.js +++ b/lib/fdfs.js @@ -292,25 +292,6 @@ function _normalizeUploadParams(file, options) { return; } - if (is.string(file)) { - fs.stat(file, function(err, stats) { - if (err || !stats) { - reject(new Error('File [' + file + '] is not exists!')); - return; - } - - options.size = stats.size; - if (!options.ext) { - options.ext = path.extname(file); - if (options.ext) { - // 去掉. - options.ext = options.ext.substring(1); - } - } - resolve(); - }); - return; - } if (is.readableStream(file) && !options.size) { reject(new Error('when the "file" parameter\'s is ReadableStream, options.size must specified')); @@ -348,6 +329,19 @@ function _normalizeUploadParams(file, options) { reject(new Error('options.offset must be a number')); } } + + if (is.string(file)) { + var stats = fs.statSync(file); + options.size = stats.size; + if (!options.ext) { + options.ext = path.extname(file); + if (options.ext) { + // 去掉. + options.ext = options.ext.substring(1); + } + } + resolve(); + } resolve(); }); diff --git a/lib/storage.js b/lib/storage.js index 689f5df..6af4918 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -281,10 +281,8 @@ Storage.prototype.upload = function(file, options) { return this._appendFile(file, options); } else if (options.method === protocol.FDFS_METHOD_MODIFY_FILE) { return this._modifyFile(file, options); - } else { - var err = new Error("options.method must in ['upload', 'uploadAppender', 'append', 'modify'] "); - throw err; } + return Promise.reject(new Error("options.method must in ['upload', 'uploadAppender', 'append', 'modify'] ")); }; /** diff --git a/package.json b/package.json index e9e7a03..91d509c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fdfs", - "version": "0.9.0", + "version": "0.9.1", "description": "FastDFS node client", "main": "index.js", "scripts": { diff --git a/test/FdfsTest.js b/test/FdfsTest.js index 37acb70..d93651c 100644 --- a/test/FdfsTest.js +++ b/test/FdfsTest.js @@ -7,7 +7,7 @@ var FdfsClient = require('../index.js'); var fdfs = new FdfsClient({ trackers: [ { - host: '192.168.0.11', + host: '192.168.0.120', port: 22122 }, {