11use super :: {
22 calculate_hash,
3- data_display_options:: { DataDisplayOptions , LevelConversion , RowParseErrorHandling } ,
3+ data_display_options:: { DataDisplayOptions , LevelConversion , RowParseErrorHandling , SizeUnits } ,
44} ;
55use anyhow:: Context ;
66use data_iter:: DataIter ;
@@ -25,6 +25,7 @@ pub struct Data {
2525 rows : Vec < LogRow > ,
2626 filtered_rows : Option < Vec < usize > > ,
2727 applied_filter : Option < FilterConfig > ,
28+ pub file_size : String ,
2829}
2930
3031#[ derive( serde:: Deserialize , serde:: Serialize , Default , Debug , PartialEq , Eq , Clone ) ]
@@ -451,7 +452,17 @@ impl TryFrom<(&DataDisplayOptions, &str)> for Data {
451452 fn try_from (
452453 ( data_display_options, value) : ( & DataDisplayOptions , & str ) ,
453454 ) -> Result < Self , Self :: Error > {
454- let mut result = Data :: default ( ) ;
455+ let file_size = SizeUnits :: Auto . convert ( value. len ( ) ) ;
456+ let file_size = file_size
457+ . as_str ( )
458+ . map ( |x| x. to_string ( ) )
459+ . unwrap_or_else ( || file_size. to_string ( ) )
460+ . trim_matches ( '0' )
461+ . to_string ( ) ;
462+ let mut result = Data {
463+ file_size,
464+ ..Default :: default ( )
465+ } ;
455466 for ( i, line) in value. lines ( ) . enumerate ( ) {
456467 let row = LogRow :: try_from ( ( data_display_options, i, line) )
457468 . with_context ( || format ! ( "failed to parse line {}" , i + 1 ) ) ?;
0 commit comments