-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cloud-mouse
committed
Sep 27, 2024
1 parent
83a7315
commit 91a5d71
Showing
12 changed files
with
98 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// import { creatChunk } from './createChunk.js' | ||
self.importScripts('spark-md5.js'); | ||
|
||
function createChunk(file, index, chunkSize) { | ||
try { | ||
return new Promise((resolve, reject) => { | ||
let start = index * chunkSize | ||
let end = start + chunkSize | ||
const spark = new SparkMD5.ArrayBuffer() | ||
const fileReader = new FileReader() | ||
fileReader.onload = (e) => { | ||
spark.append(e.target.result) | ||
resolve({ | ||
start, | ||
end, | ||
index, | ||
hash: spark.end(), | ||
}) | ||
} | ||
fileReader.readAsArrayBuffer(file.slice(start, end)) | ||
fileReader.onerror = (err) => { | ||
reject(err) // 如果读取错误,则拒绝Promise | ||
} | ||
}) | ||
} catch (error) { | ||
console.log(error); | ||
|
||
} | ||
} | ||
|
||
self.onmessage = async (e) => { | ||
try { | ||
const promises = [] | ||
const { file, chunkSize, startIndex, endIndex } = e.data | ||
for (let i = startIndex; i < endIndex; i++) { | ||
const chunk = createChunk(file, i, chunkSize) | ||
promises.push(chunk) | ||
} | ||
const chunks = await Promise.all(promises) | ||
self.postMessage(chunks) | ||
} catch (error) { | ||
self.postMessage(error) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<div class="bg-#fff p-36px"> | ||
<input type="file" name="" @change="handleFileChange"> | ||
<hr> | ||
<el-button @click="handleUpload"> | ||
点击上传 | ||
</el-button> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { cutFile } from './file_utils/cutFile' | ||
const uploadFile = ref<File | null>(null) | ||
const handleFileChange = (e) => { | ||
const file = e.target.files[0] | ||
uploadFile.value = file | ||
} | ||
const handleUpload = async () => { | ||
if (!uploadFile.value) | ||
return | ||
console.log(Date.now()) | ||
const result = await cutFile(uploadFile.value) | ||
console.log(Date.now()) | ||
console.log(result) | ||
} | ||
</script> |