Explorar el Código

更新一下吧

Gitea hace 1 año
padre
commit
20fa2a684f
Se han modificado 6 ficheros con 32 adiciones y 6 borrados
  1. 6 3
      animation/animation.js
  2. 1 1
      cutFile/createChunk.js
  3. 0 0
      cutFile/cutFile.js
  4. 0 0
      cutFile/worker.js
  5. 22 0
      index.html
  6. 3 2
      main.js

+ 6 - 3
tools/animation.js → animation/animation.js

@@ -3,14 +3,17 @@
  * @param {Function} callback 回调函数
  * @param {boolean} isEnd 是否停止
  * @param {number} duration 绘制的间隔时间(默认1s)
+ * @returns {Function}
  */
 export default function animation(callback, duration = 1000) {
   // 判断是否为函数
-  if(typeof callback !== 'function') throw new Error('callback is not a function');
+  if (typeof callback !== "function")
+    throw new Error("callback is not a function");
   // 判断是否为数字
-  if(typeof duration !== 'number') throw new Error('duration is not a number');
+  if (typeof duration !== "number") throw new Error("duration is not a number");
   // 判断是否 > 16
-  if(duration <= 16) throw new Error('duration is not a Less than or equal to 16');
+  if (duration <= 16)
+    throw new Error("duration is not a Less than or equal to 16");
 
   let time = Date.now();
   function _run() {

+ 1 - 1
tools/createChunk.js → cutFile/createChunk.js

@@ -1,4 +1,4 @@
-import SparkMD5 from './spark-md5.js';
+import SparkMD5 from '../tools/spark-md5.js';
 export function createChunk(file, index, chunkSize){
     return new Promise((resolve) => {
         const start = index * chunkSize;

+ 0 - 0
tools/cutFile.js → cutFile/cutFile.js


+ 0 - 0
tools/worker.js → cutFile/worker.js


+ 22 - 0
index.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <input type="file" id="file">
+    <script type="module">
+        import { cutFile } from "./main.js";
+        let file = document.getElementById('file');
+        file.addEventListener("change", async (e) => {
+            // let file = e.target.files[0];
+            // let result = await cutFile(file);
+            let worker = new Worker("./tools/worker.js", { type:"module" });
+            worker.postMessage("我是主线程");
+            console.log(19)
+        })
+    </script>
+</body>
+</html>

+ 3 - 2
main.js

@@ -1,5 +1,6 @@
 import { createChunk } from "./tools/createChunk.js";
 import { cutFile } from "./tools/cutFile.js";
-import animation from "./tools/animation.js";
+import animation from "./animation/animation.js";
+import SparkMD5 from "./tools/spark-md5.js";
 
-export { createChunk, cutFile, animation }
+export { createChunk, cutFile, animation, SparkMD5 }