-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile reader.html
More file actions
42 lines (35 loc) · 1.04 KB
/
File reader.html
File metadata and controls
42 lines (35 loc) · 1.04 KB
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
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text File Reader</title>
</head>
<body>
<input type="file" id="fileInput" accept=".txt" onchange="readFile()">
<pre id="output"></pre>
<script>
async function readFile() {
const fileInput = document.getElementById('fileInput');
const output = document.getElementById('output');
const file = fileInput.files[0];
if (file) {
const readableStream = file.stream().getReader();
const decoder = new TextDecoder();
let partialContent = '';
while (true) {
const { done, value } = await readableStream.read();
if (done) {
break;
}
partialContent += decoder.decode(value, { stream: true });
// Display content progressively
output.textContent = partialContent;
}
// Final update
output.textContent = partialContent;
}
}
</script>
</body>
</html>