Last active
June 5, 2017 09:19
-
-
Save nownabe/383d8c9e40d9c5ea3253fec36492d26f to your computer and use it in GitHub Desktop.
JavaScript Base64 Encoding Performance
This file contains hidden or 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> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Base64 Encoding Performance</title> | |
</head> | |
<body> | |
<p id="counter"></p> | |
<input type="file" id="dialog" multiple> | |
<p id="list"></p> | |
<script> | |
let listContent = ""; | |
const list = document.getElementById("list") | |
document.getElementById("dialog").addEventListener("change", (e) => { | |
const files = e.target.files | |
console.log(files) | |
for (let i = 0; i < files.length; i++) { | |
const file = files[i] | |
console.log(`start converting ${file.name}`) | |
const reader = new FileReader() | |
reader.readAsDataURL(file) | |
reader.onloadend = () => { | |
console.log(`finish converting ${file.name} (${reader.result.length} bytes)`) | |
listContent += `${file.name}<br>` | |
list.innerHTML = listContent | |
} | |
} | |
}) | |
let count = 0 | |
const counter = document.getElementById("counter") | |
setInterval(() => { | |
counter.innerText = count | |
count++ | |
}, 10) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment