-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
57 lines (47 loc) · 1.63 KB
/
example.js
File metadata and controls
57 lines (47 loc) · 1.63 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Example usage of file-size-humanizer
*/
const { humanize, format } = require('./index.js');
console.log('=== File Size Humanizer - Examples ===\n');
// Example 1: Small file
console.log('Example 1: 1024 bytes');
console.log(humanize(1024));
console.log('');
// Example 2: Medium file (1MB)
console.log('Example 2: 1,048,576 bytes (1 MiB)');
console.log(humanize(1048576));
console.log('');
// Example 3: Large file (1GB)
console.log('Example 3: 1,073,741,824 bytes (1 GiB)');
console.log(humanize(1073741824));
console.log('');
// Example 4: Various file sizes with format function
console.log('Example 4: Using format function');
const sizes = [
500, // 500 bytes
1024, // 1 KiB
1000000, // 1 MB
1048576, // 1 MiB
5000000000, // 5 GB
5368709120 // 5 GiB
];
sizes.forEach(size => {
console.log(`${size.toLocaleString()} bytes:`);
console.log(` Decimal: ${format(size)}`);
console.log(` Binary: ${format(size, { binary: true })}`);
});
console.log('\n=== Comparing Decimal vs Binary ===\n');
// Show the difference between decimal and binary for common file sizes
const testSizes = [
{ bytes: 1000, name: '1 KB (decimal)' },
{ bytes: 1024, name: '1 KiB (binary)' },
{ bytes: 1000000, name: '1 MB (decimal)' },
{ bytes: 1048576, name: '1 MiB (binary)' },
{ bytes: 1000000000, name: '1 GB (decimal)' },
{ bytes: 1073741824, name: '1 GiB (binary)' }
];
testSizes.forEach(({ bytes, name }) => {
const result = humanize(bytes);
console.log(`${name}:`);
console.log(` ${bytes.toLocaleString()} bytes = ${result.decimal.string} (decimal) = ${result.binary.string} (binary)`);
});