Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon he committed Jul 28, 2022
1 parent 8e8a075 commit 29ee385
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

53 changes: 27 additions & 26 deletions src/fileSplice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SparkMD5 from 'spark-md5'
import type { FileChunk, FileMD5 } from './types'

export async function fileSplice(_file: File, _chunkSize: number = 1024 * 100): Promise<FileChunk[]> {
const { HASH, suffix } = await getMD5(_file)
const { HASH, suffix } = await getMD5()
const chunks: FileChunk[] = []
// 实现切片处理 [固定切片大小 & 数量]
let max = _chunkSize // 100kb
Expand All @@ -21,31 +21,32 @@ export async function fileSplice(_file: File, _chunkSize: number = 1024 * 100):
index++
}
return chunks
}

function getMD5(_file: File): Promise<FileMD5> {
const fileReader = new FileReader()
fileReader.readAsArrayBuffer(_file)
return new Promise((resolve, reject) => {
try {
fileReader.onload = function (e: any) {
const buffer = e?.target.result; const // buffer编码
spark = new SparkMD5.ArrayBuffer()
spark.append(buffer)
const HASH = spark.end()
const suffix = /\.([a-zA-Z0-9]+)$/.exec(_file.name)![1]
const filename = `${HASH}.${suffix}`
resolve({
HASH,
suffix,
filename,
buffer,
})
function getMD5(): Promise<FileMD5> {
const fileReader = new FileReader()
fileReader.readAsArrayBuffer(_file)
return new Promise((resolve, reject) => {
try {
fileReader.onload = function (e: any) {
const buffer = e?.target.result; const // buffer编码
spark = new SparkMD5.ArrayBuffer()
spark.append(buffer)
const HASH = spark.end()
const suffix = /\.([a-zA-Z0-9]+)$/.exec(_file.name)![1]
const filename = `${HASH}.${suffix}`
resolve({
HASH,
suffix,
filename,
buffer,
})
}
}
}
catch (error: any) {
reject(new Error(error))
}
})
catch (error: any) {
reject(new Error(error))
}
})
}
}



0 comments on commit 29ee385

Please sign in to comment.