export function getFileMd5(file) {
let chunkSize = 2097152, // 2M
chunks = Math.ceil(file.size / chunkSize),
currentChunk = 0,
spark = new SparkMD5.ArrayBuffer(),
fileReader = new FileReader(),
blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice
fileReader.onload = function (e) {
spark.append(e.target.result)
currentChunk++
if (currentChunk < chunks) {
loadNext()
} else {
console.log('fileMd5', spark.end())
}
}
fileReader.onerror = function (e) {
// 出错
}
function loadNext() {
let start = currentChunk * chunkSize
let end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end))
}
loadNext()
}
使用crypto fs
-时间戳
-uuid
网友评论