mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:55:07 +02:00
Move filesize to use bigint (#2984)
* Move filesize to be bigint-sized * Add tests and fix filesize display * clippy
This commit is contained in:
@ -631,8 +631,8 @@ impl Unit {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filesize(size_in_bytes: u64) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Filesize(size_in_bytes))
|
||||
pub fn filesize(size_in_bytes: impl Into<BigInt>) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Filesize(size_in_bytes.into()))
|
||||
}
|
||||
|
||||
pub fn duration(nanos: BigInt) -> UntaggedValue {
|
||||
|
@ -186,7 +186,7 @@ impl UntaggedValue {
|
||||
}
|
||||
|
||||
/// Helper for creating filesize values
|
||||
pub fn filesize(s: impl Into<u64>) -> UntaggedValue {
|
||||
pub fn filesize(s: impl Into<BigInt>) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Filesize(s.into()))
|
||||
}
|
||||
|
||||
@ -713,7 +713,7 @@ impl U64Ext for u64 {
|
||||
|
||||
fn to_filesize_value(&self, the_tag: Tag) -> Value {
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::Filesize(*self)),
|
||||
value: UntaggedValue::Primitive(Primitive::Filesize(BigInt::from(*self))),
|
||||
tag: the_tag,
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ pub enum Primitive {
|
||||
#[serde(with = "serde_bigdecimal")]
|
||||
Decimal(BigDecimal),
|
||||
/// A count in the number of bytes, used as a filesize
|
||||
Filesize(u64),
|
||||
Filesize(BigInt),
|
||||
/// A string value
|
||||
String(String),
|
||||
/// A path to travel to reach a value in a table
|
||||
@ -254,17 +254,21 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
||||
Primitive::EndOfStream => String::new(),
|
||||
Primitive::FilePath(p) => format!("{}", p.display()),
|
||||
Primitive::Filesize(num_bytes) => {
|
||||
let byte = byte_unit::Byte::from_bytes(*num_bytes as u128);
|
||||
if let Some(value) = num_bytes.to_u128() {
|
||||
let byte = byte_unit::Byte::from_bytes(value);
|
||||
|
||||
if byte.get_bytes() == 0u128 {
|
||||
return "—".to_string();
|
||||
}
|
||||
if byte.get_bytes() == 0u128 {
|
||||
return "—".to_string();
|
||||
}
|
||||
|
||||
let byte = byte.get_appropriate_unit(false);
|
||||
let byte = byte.get_appropriate_unit(false);
|
||||
|
||||
match byte.get_unit() {
|
||||
byte_unit::ByteUnit::B => format!("{} B ", byte.get_value()),
|
||||
_ => byte.format(1),
|
||||
match byte.get_unit() {
|
||||
byte_unit::ByteUnit::B => format!("{} B ", byte.get_value()),
|
||||
_ => byte.format(1),
|
||||
}
|
||||
} else {
|
||||
format!("{} B", num_bytes)
|
||||
}
|
||||
}
|
||||
Primitive::Duration(duration) => format_duration(duration),
|
||||
|
Reference in New Issue
Block a user