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
<!DOCTYPE html> | |
<html lang="zh-CN"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>大文件并发上传示例(阿宝哥)</title> | |
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script> | |
<script src="https://cdn.bootcdn.net/ajax/libs/spark-md5/3.0.0/spark-md5.min.js"></script> | |
</head> |
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
<!DOCTYPE html> | |
<html lang="zh-cn"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Transmat Source 示例</title> | |
<script src="https://unpkg.com/transmat/lib/index.umd.js"></script> | |
<style> | |
body { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>File Type Detect Demo</title> | |
</head> | |
<body> | |
<div> |
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
function asyncPool(concurrency, iterable, iteratorFn) { | |
let i = 0; | |
const ret = []; // // Store all asynchronous tasks | |
const executing = new Set(); // Stores executing asynchronous tasks | |
const enqueue = function() { | |
if (i === iterable.length) { | |
return Promise.resolve(); | |
} | |
const item = iterable[i++]; // Get the new task item | |
const p = Promise.resolve().then(() => iteratorFn(item, iterable)); |
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
async function asyncPool(concurrency, iterable, iteratorFn) { | |
const ret = []; // Store all asynchronous tasks | |
const executing = new Set(); // Stores executing asynchronous tasks | |
for (const item of iterable) { | |
// Call the iteratorFn function to create an asynchronous task | |
const p = Promise.resolve().then(() => iteratorFn(item, iterable)); | |
ret.push(p); // save new async task | |
executing.add(p); // Save an executing asynchronous task | |
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
Promise.all = function (iterators) { | |
return new Promise((resolve, reject) => { | |
if (!iterators || iterators.length === 0) { | |
resolve([]); | |
} else { | |
// used to determine whether all tasks are completed | |
let count = 0; | |
let result = []; // result array | |
for (let i = 0; i < iterators.length; i++) { | |
// Considering that iterators[i] may be ordinary object, |
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
Promise.race = function (iterators) { | |
return new Promise((resolve, reject) => { | |
for (const iter of iterators) { | |
Promise.resolve(iter) | |
.then((res) => { | |
resolve(res); | |
}) | |
.catch((e) => { | |
reject(e); | |
}); |
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
function getBinaryContent(url, start, end, i) { | |
return new Promise((resolve, reject) => { | |
try { | |
let xhr = new XMLHttpRequest(); | |
xhr.open("GET", url, true); | |
xhr.setRequestHeader("range", `bytes=${start}-${end}`); // Set range request information | |
xhr.responseType = "arraybuffer"; // Set the returned type to arraybuffer | |
xhr.onload = function () { | |
resolve({ | |
index: i, // file block index |
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
function concatenate(arrays) { | |
if (!arrays.length) return null; | |
let totalLength = arrays.reduce((acc, value) => acc + value.length, 0); | |
let result = new Uint8Array(totalLength); | |
let length = 0; | |
for (let array of arrays) { | |
result.set(array, length); | |
length += array.length; | |
} | |
return result; |
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
function getContentLength(url) { | |
return new Promise((resolve, reject) => { | |
let xhr = new XMLHttpRequest(); | |
xhr.open("HEAD", url); | |
xhr.send(); | |
xhr.onload = function () { | |
resolve( | |
~~xhr.getResponseHeader("Content-Length") | |
); | |
}; |