mirror of
https://github.com/DarrylNixon/binhop
synced 2024-04-22 12:37:06 -07:00
Still deciding on output
This commit is contained in:
parent
60524bf2dc
commit
02e660538f
2 changed files with 99 additions and 11 deletions
|
@ -1,3 +1,42 @@
|
|||
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);
|
||||
|
@ -39,7 +78,7 @@ async function process_upload(file) {
|
|||
</tr>
|
||||
<tr>
|
||||
<th><strong>size:</strong></th>
|
||||
<td>${data.meta.sizeb} (${data.meta.sizeh})</td>
|
||||
<td>${data.meta["sizeb"]} (${bytes_to_human(data.meta.sizeb)})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><strong>sha1:</strong></th>
|
||||
|
@ -66,6 +105,7 @@ async function process_upload(file) {
|
|||
</small>
|
||||
</div>
|
||||
</div>`;
|
||||
draw_bytes(data);
|
||||
} else {
|
||||
console.error('error uploading file');
|
||||
}
|
||||
|
@ -79,4 +119,4 @@ async function process_upload(file) {
|
|||
process_upload(file);
|
||||
});
|
||||
fileInput.click();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue