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>Concurrent Download Demo</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
const fs = require("fs"); | |
const path = require("path"); | |
const util = require("util"); | |
const Koa = require("koa"); | |
const cors = require("@koa/cors"); | |
const multer = require("@koa/multer"); | |
const Router = require("@koa/router"); | |
const serve = require("koa-static"); | |
const fse = require("fs-extra"); | |
const readdir = util.promisify(fs.readdir); |
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 uploadFile() { | |
if (!uploadFileEle.files.length) return; | |
const file = uploadFileEle.files[0]; | |
const fileMd5 = await calcFileMD5(file); // Calculate the MD5 of the file | |
const fileStatus = await checkFileExist( | |
// Check if the file already exists | |
"/exists", | |
file.name, | |
fileMd5 | |
); |
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 upload({ | |
url, | |
file, | |
fileMd5, | |
fileSize, | |
chunkSize, | |
chunkIds, | |
poolLimit = 1, | |
}) { | |
const chunks = |
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 calcFileMD5(file) { | |
return new Promise((resolve, reject) => { | |
let chunkSize = 2097152, // 2M | |
chunks = Math.ceil(file.size / chunkSize), | |
currentChunk = 0, | |
spark = new SparkMD5.ArrayBuffer(), | |
fileReader = new FileReader(); | |
fileReader.onload = (e) => { | |
spark.append(e.target.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
<!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>Range Request Demo (Bytefer)</title> | |
</head> | |
<body> | |
<h3>Range Request Demo (Bytefer)</h3> |
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
const Koa = require("koa"); | |
const cors = require("@koa/cors"); | |
const serve = require("koa-static"); | |
const range = require("koa-range"); | |
const app = new Koa(); | |
// register middlewares | |
app.use(cors()); | |
app.use(range); |
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
const fs = require("fs"); | |
const zlib = require("zlib"); | |
const http = require("http"); | |
http | |
.createServer((req, res) => { | |
res.writeHead(200, { | |
"Content-Type": "text/plain;charset=utf-8", | |
"Content-Encoding": "gzip", | |
}); |
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
const fs = require("fs"); | |
const http = require("http"); | |
const buffer = fs.readFileSync(__dirname + "/first-100-lines.txt"); | |
const lines = buffer.toString("utf-8").split("\n"); | |
const chunks = chunk(lines, 10); | |
function chunk(arr, len) { | |
let chunks = [], | |
i = 0, |
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
const fs = require("fs"); | |
const zlib = require("zlib"); | |
const http = require("http"); | |
const util = require("util"); | |
const readFile = util.promisify(fs.readFile); | |
const gzip = util.promisify(zlib.gzip); | |
const server = http.createServer(async (req, res) => { | |
res.writeHead(200, { | |
"Content-Type": "text/plain;charset=utf-8", |