-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (29 loc) · 1.21 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
document.addEventListener("DOMContentLoaded", function () {
const jsonContent = document.getElementById("jsonContent");
const jsonFileInput = document.getElementById("jsonFile");
jsonFileInput.addEventListener("change", function (e) {
const file = e.target.files[0];
if (file) {
(async () => {
jsonContent.innerHTML = '';
const size = 1024 * 500; // === 500kb
for (var offset = 0; offset < file.size; offset += size) {
var text = await file.slice(offset, offset + size).text();
jsonContent.innerHTML += text;
}
// const fileContentStream = await file.stream();
// await streamToText(fileContentStream)
})();
}
});
// const streamToText = async (blob) => {
// /*cria leitor de stream a partir de um obj blob */
// const readableStream = await blob.getReader();
// /*ler pedaços de dados (chunk) da stream criada*/
// const chunk = await readableStream.read();
// /*cria novo obj textdecoder, q decodifica dados binarios em texto
// e converte o valor de chunk em texto usando utf 8*/
// const text = new TextDecoder('utf-8').decode(chunk.value);
// jsonContent.innerHTML = text;
// };
});