Skip to content

Commit 29ee385

Browse files
author
Simon he
committed
chore: update
1 parent 8e8a075 commit 29ee385

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/fileSplice.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SparkMD5 from 'spark-md5'
22
import type { FileChunk, FileMD5 } from './types'
33

44
export async function fileSplice(_file: File, _chunkSize: number = 1024 * 100): Promise<FileChunk[]> {
5-
const { HASH, suffix } = await getMD5(_file)
5+
const { HASH, suffix } = await getMD5()
66
const chunks: FileChunk[] = []
77
// 实现切片处理 [固定切片大小 & 数量]
88
let max = _chunkSize // 100kb
@@ -21,31 +21,32 @@ export async function fileSplice(_file: File, _chunkSize: number = 1024 * 100):
2121
index++
2222
}
2323
return chunks
24-
}
25-
26-
function getMD5(_file: File): Promise<FileMD5> {
27-
const fileReader = new FileReader()
28-
fileReader.readAsArrayBuffer(_file)
29-
return new Promise((resolve, reject) => {
30-
try {
31-
fileReader.onload = function (e: any) {
32-
const buffer = e?.target.result; const // buffer编码
33-
spark = new SparkMD5.ArrayBuffer()
34-
spark.append(buffer)
35-
const HASH = spark.end()
36-
const suffix = /\.([a-zA-Z0-9]+)$/.exec(_file.name)![1]
37-
const filename = `${HASH}.${suffix}`
38-
resolve({
39-
HASH,
40-
suffix,
41-
filename,
42-
buffer,
43-
})
24+
function getMD5(): Promise<FileMD5> {
25+
const fileReader = new FileReader()
26+
fileReader.readAsArrayBuffer(_file)
27+
return new Promise((resolve, reject) => {
28+
try {
29+
fileReader.onload = function (e: any) {
30+
const buffer = e?.target.result; const // buffer编码
31+
spark = new SparkMD5.ArrayBuffer()
32+
spark.append(buffer)
33+
const HASH = spark.end()
34+
const suffix = /\.([a-zA-Z0-9]+)$/.exec(_file.name)![1]
35+
const filename = `${HASH}.${suffix}`
36+
resolve({
37+
HASH,
38+
suffix,
39+
filename,
40+
buffer,
41+
})
42+
}
4443
}
45-
}
46-
catch (error: any) {
47-
reject(new Error(error))
48-
}
49-
})
44+
catch (error: any) {
45+
reject(new Error(error))
46+
}
47+
})
48+
}
5049
}
5150

51+
52+

0 commit comments

Comments
 (0)