8
8
from unstract .sdk .constants import MetadataKey , PropKey
9
9
from unstract .sdk .tool .base import BaseTool
10
10
from unstract .sdk .tool .mime_types import EXT_MIME_MAP
11
+ from unstract .sdk .utils import Utils
11
12
12
13
13
14
def extend_with_default (validator_class : Any ) -> Any :
@@ -119,7 +120,7 @@ def _validate_file_size(self, input_file: Path) -> None:
119
120
f"Checking input file size... (max file size: { max_file_size } )"
120
121
)
121
122
file_size = self .tool .workflow_filestorage .size (path = input_file )
122
- self .tool .stream_log (f"Input file size: { self . _human_readable_size (file_size )} " )
123
+ self .tool .stream_log (f"Input file size: { Utils . pretty_file_size (file_size )} " )
123
124
124
125
if file_size > max_size_in_bytes :
125
126
source_name = self .tool .get_exec_metadata .get (MetadataKey .SOURCE_NAME )
@@ -128,22 +129,6 @@ def _validate_file_size(self, input_file: Path) -> None:
128
129
f"allowed size of { max_file_size } "
129
130
)
130
131
131
- def _human_readable_size (self , num : float , suffix : str = "B" ) -> str :
132
- """Gets the human readable size for a file,
133
-
134
- Args:
135
- num (int): Size in bytes to parse
136
- suffix (str, optional): _description_. Defaults to "B".
137
-
138
- Returns:
139
- str: Human readable size
140
- """
141
- for unit in ("" , "K" , "M" , "G" , "T" ):
142
- if abs (num ) < 1024.0 :
143
- return f"{ num :3.1f} { unit } { suffix } "
144
- num /= 1024.0
145
- return f"{ num :.1f} { suffix } "
146
-
147
132
def _parse_size_string (self , size_string : str ) -> int :
148
133
"""Parses the size string for validation.
149
134
0 commit comments