Skip to content

Instantly share code, notes, and snippets.

@nownabe
Last active June 5, 2017 09:19
Show Gist options
  • Save nownabe/383d8c9e40d9c5ea3253fec36492d26f to your computer and use it in GitHub Desktop.
Save nownabe/383d8c9e40d9c5ea3253fec36492d26f to your computer and use it in GitHub Desktop.
JavaScript Base64 Encoding Performance
<!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