Permalink
Browse files

fix fd close and enableCrc32Check bug

  • Loading branch information...
1 parent 702ac42 commit b46acbfafd7376f45e515e3d92386dec7dc191d2 @ikbear committed Jan 14, 2013
Showing with 12 additions and 14 deletions.
  1. +0 −1 CHANGELOG.md
  2. +9 −8 lib/rs.js
  3. +3 −5 lib/util.js
View
@@ -16,4 +16,3 @@ updated:
updated:
- 启用新的 uploadToken(上传凭证)上传方式,可由客户方业务服务器生成上传凭证。上传前无需请求七牛云存储,减少http请求。
-- 增加断点续上传支持,并行断点传输速度更快
View
@@ -117,16 +117,17 @@ Service.prototype.uploadFile = function(upToken, key, mimeType, localFile, onret
});
};
-Service.prototype.uploadWithToken = function(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, fileCrc32, onret) {
+Service.prototype.uploadWithToken = function(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) {
/*
- * func UploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, fileCrc32, onret) => (data PutRet, code int, err Error)
+ * func UploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) => (data PutRet, code int, err Error)
* 使用upload_token以multipart/form-data形式上传ReadStream流
**/
var bucket = this.bucket;
if (!mimeType) {
mimeType = "application/octet-stream";
}
- var actionString = util.generateActionString(bucket, key, mimeType, customMeta, enableCrc32Check, fileCrc32);
+
+ var actionString = util.generateActionString(bucket, key, mimeType, customMeta, enableCrc32Check);
if (callbackParams === null) {
callbackParams = {
"bucket": bucket,
@@ -164,20 +165,20 @@ Service.prototype.uploadFileWithToken = function(uploadToken, localFile, key, mi
onret({code: -1, error: err.toString(), detail: err});
return;
}
- var fileCrc32 = ''
- , stream = fs.createReadStream(localFile);
+ var stream = fs.createReadStream(localFile);
if (enableCrc32Check) {
var fileStat = fs.statSync(localFile)
, fileSize = fileStat.size
, buf = new Buffer(fileSize)
, fd = fs.openSync(localFile, 'r');
-
+
fs.readSync(fd, buf, 0, fileSize, 0);
- fileCrc32 = parseInt("0x" + crc32(buf)).toString();
+ fs.closeSync(fd);
+ enableCrc32Check = parseInt("0x" + crc32(buf)).toString();
}
- return self.uploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, fileCrc32, onret);
+ self.uploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret);
});
};
View
@@ -15,7 +15,7 @@ exports.encode = function(v) {
return exports.base64ToUrlsafe(encoded);
};
-exports.generateActionString = function(bucket, key, mimeType, customMeta, enableCrc32Check, fileCrc32) {
+exports.generateActionString = function(bucket, key, mimeType, customMeta, enableCrc32Check) {
if (!key) {
console.error("Please specify your key!");
return;
@@ -29,10 +29,8 @@ exports.generateActionString = function(bucket, key, mimeType, customMeta, enabl
actionParams += '/meta/' + this.encode(customMeta);
}
if (enableCrc32Check) {
- if ((fileCrc32 !== undefined) && (fileCrc32 !== null)) {
- actionParams += '/crc32/' + fileCrc32;
- }
- }
+ actionParams += '/crc32/' + enableCrc32Check;
+ }
return actionParams;
}

0 comments on commit b46acbf

Please sign in to comment.