function draw_bytes(data) { const canvas = document.getElementById("blob"); const ctx = canvas.getContext("2d"); // canvas.width = canvas.parentNode.width; // canvas.height = canvas.parentNode.height; const blockSize = 2; const blockPadding = 1; ctx.fillStyle = "#ddd"; const numBlocks = Math.ceil(data.meta.sizeb / (blockSize + blockPadding)); for (let i = 0; i < numBlocks; i++) { const x = i * (blockSize + blockPadding); ctx.fillRect(x, 0, blockSize, canvas.height); } ctx.fillStyle = "blue"; data.offsets.forEach((offset) => { const start = Math.floor(offset.start / (blockSize + blockPadding)); const end = Math.ceil(offset.end / (blockSize + blockPadding)); for (let i = start; i < end; i++) { const x = i * (blockSize + blockPadding); ctx.fillRect(x, 0, blockSize, canvas.height); } }); } function bytes_to_human(bytes) { const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; let i =0; while (bytes >= 1024 && i < units.length - 1) { bytes /= 1024; i++; } return bytes.toFixed(2) + " " + units[i]; } async function process_upload(file) { const formData = new FormData(); formData.append('file', file); const button = document.querySelector('button'); button.setAttribute('aria-busy', 'true'); button.textContent = `processing ${file.name}...`; const response = await fetch('api/upload_file', { method: 'POST', body: formData, timeout: 600000 // 10 minutes }); if (response.ok) { const data = await response.json(); const container = document.querySelector('.container'); // visualization container.innerHTML = `

${data.meta.name}

blob meta
filename: ${data.meta.name}
process duration: ${data.meta.duration}
size: ${data.meta["sizeb"]} (${bytes_to_human(data.meta.sizeb)})
sha1: ${data.meta.sha1}
md5: ${data.meta.md5}
Header
Body
Footer
Header
Body
Footer
${JSON.stringify(data, null, 2)}
`; draw_bytes(data); } else { console.error('error uploading file'); } } function upload_file() { const fileInput = document.createElement('input'); fileInput.type = 'file'; fileInput.addEventListener('change', (event) => { const file = event.target.files[0]; process_upload(file); }); fileInput.click(); }