Skip to content

Commit 207d295

Browse files
simonwclaude
andauthored
Add file sizes next to filenames in zip-wheel-explorer (#255)
Shows human-readable file sizes (bytes/KB/MB) next to each filename in the file listing, using the most appropriate unit for each file. https://claude.ai/code/session_01Rh44SzVc2P6pixRfeA1EKN Co-authored-by: Claude <noreply@anthropic.com>
1 parent afc4531 commit 207d295

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

zip-wheel-explorer.html

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
.file-item:active {
8888
background: #e8e8e8;
8989
}
90+
.file-size {
91+
color: #999;
92+
font-size: 0.75rem;
93+
margin-left: 0.5em;
94+
white-space: nowrap;
95+
}
9096
.file-item.selected {
9197
background: #e7f1ff;
9298
border-bottom: none;
@@ -357,8 +363,14 @@ <h1>Package File Browser</h1>
357363
files.forEach((file, index) => {
358364
const fileEl = document.createElement('div');
359365
fileEl.className = 'file-item';
360-
fileEl.textContent = file.name;
361366
fileEl.dataset.filename = file.name;
367+
const nameSpan = document.createElement('span');
368+
nameSpan.textContent = file.name;
369+
const sizeSpan = document.createElement('span');
370+
sizeSpan.className = 'file-size';
371+
sizeSpan.textContent = formatFileSize(file.size);
372+
fileEl.appendChild(nameSpan);
373+
fileEl.appendChild(sizeSpan);
362374
fileEl.onclick = () => selectFile(file.name, null);
363375
fileListEl.appendChild(fileEl);
364376
});
@@ -377,12 +389,19 @@ <h1>Package File Browser</h1>
377389
return div.innerHTML;
378390
}
379391

392+
function formatFileSize(bytes) {
393+
if (bytes >= 1048576) return (bytes / 1048576).toFixed(1) + ' MB';
394+
if (bytes >= 1024) return (bytes / 1024).toFixed(1) + ' KB';
395+
return bytes + ' bytes';
396+
}
397+
380398
async function extractFiles(arrayBuffer, url) {
381399
const files = [];
382400
const zip = await JSZip.loadAsync(arrayBuffer);
383401
for (const [name, file] of Object.entries(zip.files)) {
384402
const content = await file.async('text');
385-
files.push({ name, content });
403+
const rawBytes = await file.async('uint8array');
404+
files.push({ name, content, size: rawBytes.byteLength });
386405
}
387406
return files;
388407
}

0 commit comments

Comments
 (0)