Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ function readableSize(size) {
if (1 === size) {
return '1 Byte';
}
const i = Math.floor(Math.log(size) / Math.log(1024));
// 0 has no logarithm, so it is counted in bytes
const i = size ? Math.floor(Math.log(size) / Math.log(1024)) : 0;
return (
(size / Math.pow(1024, i)).toFixed(!!i ? 1 : 0) + ' ' + ['Bytes', 'KB', 'MB', 'GB', 'TB'][i]
);
Expand Down
2 changes: 1 addition & 1 deletion test/js/replacement-js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('--replacement-js', () => {
expect(await js('foobar', 'bytes + "|" + size', 'foobar')).toBe('6|6 Bytes');
});

test.todo('BUG #687: size of empty content is "0 Bytes"', async () => {
test('size of empty content is "0 Bytes" (#687)', async () => {
expect(await inFile('bytes + "|" + size', '')).toBe('0|0 Bytes');
});

Expand Down
Loading