diff options
author | Thomas Hurst <tom@hur.st> | 2020-07-01 20:28:38 +0000 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-07-02 06:44:12 +0800 |
commit | 1d8ba524ac83a0c3b5e4146cf937ed75650f1e97 (patch) | |
tree | 82852377479372a176a8b5491dea22e999b6ec6b /src/common.rs | |
parent | c37ee449f32ed3af0fc222f669ae3f40859d8a39 (diff) |
Use u128 for byte sizes
Per issue #58, u64 is insufficient for use with very large sparse files.
Enormous file sizes are also a common filesystem error trope, either
from disk corruption or software bugs, and they're also conceivable with
virtual filesystems.
Handle this as gracefully as can be reasonably expected using 128-bit
integers, which should be sufficient for most uses.
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common.rs b/src/common.rs index e5cf697..d297c45 100644 --- a/src/common.rs +++ b/src/common.rs @@ -7,7 +7,7 @@ pub fn get_entry_or_panic(tree: &Tree, node_idx: TreeIndex) -> &EntryData { .expect("node should always be retrievable with valid index") } -pub(crate) fn get_size_or_panic(tree: &Tree, node_idx: TreeIndex) -> u64 { +pub(crate) fn get_size_or_panic(tree: &Tree, node_idx: TreeIndex) -> u128 { get_entry_or_panic(tree, node_idx).size } @@ -52,7 +52,7 @@ impl ByteFormat { } + THE_SPACE_BETWEEN_UNIT_AND_NUMBER } - pub fn display(self, bytes: u64) -> ByteFormatDisplay { + pub fn display(self, bytes: u128) -> ByteFormatDisplay { ByteFormatDisplay { format: self, bytes, @@ -62,7 +62,7 @@ impl ByteFormat { pub struct ByteFormatDisplay { format: ByteFormat, - bytes: u64, + bytes: u128, } impl fmt::Display for ByteFormatDisplay { @@ -84,7 +84,7 @@ impl fmt::Display for ByteFormatDisplay { (_, Some((divisor, unit))) => Byte::from_unit(self.bytes as f64 / divisor as f64, unit) .expect("byte count > 0") .get_adjusted_unit(unit), - (binary, None) => Byte::from_bytes(u128::from(self.bytes)).get_appropriate_unit(binary), + (binary, None) => Byte::from_bytes(self.bytes).get_appropriate_unit(binary), } .format(2); let mut splits = b.split(' '); |