forked from extern/nushell
Rename 'bytes' to 'filesize' (#2153)
This commit is contained in:
@ -497,13 +497,13 @@ impl Unit {
|
||||
let size = size.clone();
|
||||
|
||||
match self {
|
||||
Unit::Byte => bytes(convert_number_to_u64(&size)),
|
||||
Unit::Kilobyte => bytes(convert_number_to_u64(&size) * 1024),
|
||||
Unit::Megabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024),
|
||||
Unit::Gigabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024),
|
||||
Unit::Terabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024),
|
||||
Unit::Byte => filesize(convert_number_to_u64(&size)),
|
||||
Unit::Kilobyte => filesize(convert_number_to_u64(&size) * 1024),
|
||||
Unit::Megabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024),
|
||||
Unit::Gigabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024),
|
||||
Unit::Terabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024),
|
||||
Unit::Petabyte => {
|
||||
bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024 * 1024)
|
||||
filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024 * 1024)
|
||||
}
|
||||
Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")),
|
||||
Unit::Microsecond => {
|
||||
@ -571,8 +571,8 @@ impl Unit {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bytes(size: u64) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Bytes(size))
|
||||
pub fn filesize(size_in_bytes: u64) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Filesize(size_in_bytes))
|
||||
}
|
||||
|
||||
pub fn duration(nanos: BigInt) -> UntaggedValue {
|
||||
|
@ -34,7 +34,7 @@ pub enum Type {
|
||||
/// A decimal (floating point) value
|
||||
Decimal,
|
||||
/// A filesize in bytes
|
||||
Bytesize,
|
||||
Filesize,
|
||||
/// A string of text
|
||||
String,
|
||||
/// A line of text (a string with trailing line ending)
|
||||
@ -138,7 +138,7 @@ impl Type {
|
||||
Type::Range(Box::new(range))
|
||||
}
|
||||
Primitive::Decimal(_) => Type::Decimal,
|
||||
Primitive::Bytes(_) => Type::Bytesize,
|
||||
Primitive::Filesize(_) => Type::Filesize,
|
||||
Primitive::String(_) => Type::String,
|
||||
Primitive::Line(_) => Type::Line,
|
||||
Primitive::ColumnPath(_) => Type::ColumnPath,
|
||||
@ -220,7 +220,7 @@ impl PrettyDebug for Type {
|
||||
)
|
||||
}
|
||||
Type::Decimal => ty("decimal"),
|
||||
Type::Bytesize => ty("bytesize"),
|
||||
Type::Filesize => ty("filesize"),
|
||||
Type::String => ty("string"),
|
||||
Type::Line => ty("line"),
|
||||
Type::ColumnPath => ty("column-path"),
|
||||
|
@ -183,9 +183,9 @@ impl UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Path(s.into()))
|
||||
}
|
||||
|
||||
/// Helper for creating bytesize values
|
||||
pub fn bytes(s: impl Into<u64>) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Bytes(s.into()))
|
||||
/// Helper for creating filesize values
|
||||
pub fn filesize(s: impl Into<u64>) -> UntaggedValue {
|
||||
UntaggedValue::Primitive(Primitive::Filesize(s.into()))
|
||||
}
|
||||
|
||||
/// Helper for creating decimal values
|
||||
@ -282,7 +282,7 @@ impl Value {
|
||||
UntaggedValue::Primitive(Primitive::Boolean(x)) => format!("{}", x),
|
||||
UntaggedValue::Primitive(Primitive::Decimal(x)) => format!("{}", x),
|
||||
UntaggedValue::Primitive(Primitive::Int(x)) => format!("{}", x),
|
||||
UntaggedValue::Primitive(Primitive::Bytes(x)) => format!("{}", x),
|
||||
UntaggedValue::Primitive(Primitive::Filesize(x)) => format!("{}", x),
|
||||
UntaggedValue::Primitive(Primitive::Path(x)) => format!("{}", x.display()),
|
||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
|
||||
let joined = path
|
||||
|
@ -33,7 +33,7 @@ impl PrettyType for Primitive {
|
||||
Primitive::Int(_) => ty("integer"),
|
||||
Primitive::Range(_) => ty("range"),
|
||||
Primitive::Decimal(_) => ty("decimal"),
|
||||
Primitive::Bytes(_) => ty("bytesize"),
|
||||
Primitive::Filesize(_) => ty("filesize"),
|
||||
Primitive::String(_) => ty("string"),
|
||||
Primitive::Line(_) => ty("line"),
|
||||
Primitive::ColumnPath(_) => ty("column-path"),
|
||||
@ -71,7 +71,7 @@ impl PrettyDebug for Primitive {
|
||||
.group(),
|
||||
)
|
||||
}
|
||||
Primitive::Bytes(bytes) => primitive_doc(bytes, "bytesize"),
|
||||
Primitive::Filesize(bytes) => primitive_doc(bytes, "filesize"),
|
||||
Primitive::String(string) => prim(string),
|
||||
Primitive::Line(string) => prim(string),
|
||||
Primitive::ColumnPath(path) => path.pretty(),
|
||||
|
@ -31,7 +31,7 @@ pub enum Primitive {
|
||||
#[serde(with = "serde_bigdecimal")]
|
||||
Decimal(BigDecimal),
|
||||
/// A count in the number of bytes, used as a filesize
|
||||
Bytes(u64),
|
||||
Filesize(u64),
|
||||
/// A string value
|
||||
String(String),
|
||||
/// A string value with an implied carriage return (or cr/lf) ending
|
||||
@ -143,7 +143,7 @@ impl num_traits::Zero for Primitive {
|
||||
match self {
|
||||
Primitive::Int(int) => int.is_zero(),
|
||||
Primitive::Decimal(decimal) => decimal.is_zero(),
|
||||
Primitive::Bytes(size) => size.is_zero(),
|
||||
Primitive::Filesize(num_bytes) => num_bytes.is_zero(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -164,25 +164,25 @@ impl std::ops::Add for Primitive {
|
||||
(Primitive::Decimal(left), Primitive::Int(right)) => {
|
||||
Primitive::Decimal(left + BigDecimal::from(right))
|
||||
}
|
||||
(Primitive::Bytes(left), right) => match right {
|
||||
Primitive::Bytes(right) => Primitive::Bytes(left + right),
|
||||
(Primitive::Filesize(left), right) => match right {
|
||||
Primitive::Filesize(right) => Primitive::Filesize(left + right),
|
||||
Primitive::Int(right) => {
|
||||
Primitive::Bytes(left + right.to_u64().unwrap_or_else(|| 0 as u64))
|
||||
Primitive::Filesize(left + right.to_u64().unwrap_or_else(|| 0 as u64))
|
||||
}
|
||||
Primitive::Decimal(right) => {
|
||||
Primitive::Bytes(left + right.to_u64().unwrap_or_else(|| 0 as u64))
|
||||
Primitive::Filesize(left + right.to_u64().unwrap_or_else(|| 0 as u64))
|
||||
}
|
||||
_ => Primitive::Bytes(left),
|
||||
_ => Primitive::Filesize(left),
|
||||
},
|
||||
(left, Primitive::Bytes(right)) => match left {
|
||||
Primitive::Bytes(left) => Primitive::Bytes(left + right),
|
||||
(left, Primitive::Filesize(right)) => match left {
|
||||
Primitive::Filesize(left) => Primitive::Filesize(left + right),
|
||||
Primitive::Int(left) => {
|
||||
Primitive::Bytes(left.to_u64().unwrap_or_else(|| 0 as u64) + right)
|
||||
Primitive::Filesize(left.to_u64().unwrap_or_else(|| 0 as u64) + right)
|
||||
}
|
||||
Primitive::Decimal(left) => {
|
||||
Primitive::Bytes(left.to_u64().unwrap_or_else(|| 0 as u64) + right)
|
||||
Primitive::Filesize(left.to_u64().unwrap_or_else(|| 0 as u64) + right)
|
||||
}
|
||||
_ => Primitive::Bytes(right),
|
||||
_ => Primitive::Filesize(right),
|
||||
},
|
||||
_ => Primitive::zero(),
|
||||
}
|
||||
@ -270,7 +270,7 @@ impl ShellTypeName for Primitive {
|
||||
Primitive::Int(_) => "integer",
|
||||
Primitive::Range(_) => "range",
|
||||
Primitive::Decimal(_) => "decimal",
|
||||
Primitive::Bytes(_) => "bytes",
|
||||
Primitive::Filesize(_) => "filesize(in bytes)",
|
||||
Primitive::String(_) => "string",
|
||||
Primitive::Line(_) => "line",
|
||||
Primitive::ColumnPath(_) => "column path",
|
||||
@ -293,8 +293,8 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
||||
Primitive::BeginningOfStream => String::new(),
|
||||
Primitive::EndOfStream => String::new(),
|
||||
Primitive::Path(p) => format!("{}", p.display()),
|
||||
Primitive::Bytes(b) => {
|
||||
let byte = byte_unit::Byte::from_bytes(*b as u128);
|
||||
Primitive::Filesize(num_bytes) => {
|
||||
let byte = byte_unit::Byte::from_bytes(*num_bytes as u128);
|
||||
|
||||
if byte.get_bytes() == 0u128 {
|
||||
return "—".to_string();
|
||||
|
Reference in New Issue
Block a user