通过hash索引文件, 而不是按顺序

This commit is contained in:
life
2015-10-26 19:48:00 +08:00
parent 7ce5c90de8
commit a09ff973e6
2 changed files with 35 additions and 11 deletions

17
node_modules/file.js generated vendored
View File

@@ -49,17 +49,30 @@ var File = {
// return;
try {
var err = fs.writeFileSync(filePath, new Buffer(data, 'base64'));
var bf = new Buffer(data, 'base64');
var err = fs.writeFileSync(filePath, bf);
if(err) {
return callback(false);
}
// 得到文件的hash
var hash = crypto.createHash('md5');
hash.setEncoding('hex');
hash.write(bf);
hash.end();
var fileHash = hash.read();
if(isImage) {
me._addImage(Common.objectId(), filePath, function(newImg) {
newImg.IsImage = true;
newImg.hash = fileHash;
callback && callback(newImg);
});
} else {
me._addAttach(filePath, fileTitle, callback)
me._addAttach(filePath, fileTitle, function(attach) {
attach.hash = fileHash;
callback && callback(attach);
});
}
/*