Transform file size to byte :param str/int/float size: 1, '30', '20M', '32k', '16G', '15mb' :return int: in byte
(size)
| 346 | |
| 347 | |
| 348 | def parse_file_size(size): |
| 349 | """Transform file size to byte |
| 350 | |
| 351 | :param str/int/float size: 1, '30', '20M', '32k', '16G', '15mb' |
| 352 | :return int: in byte |
| 353 | """ |
| 354 | if isinstance(size, (int, float)): |
| 355 | return int(size) |
| 356 | assert isinstance(size, str), '`size` must be int/float/str, got %s' % type(size) |
| 357 | |
| 358 | size = size.lower().replace('b', '') |
| 359 | |
| 360 | for idx, i in enumerate(['k', 'm', 'g', 't', 'p'], 1): |
| 361 | if i in size: |
| 362 | s = size.replace(i, '') |
| 363 | base = 2 ** (idx * 10) |
| 364 | return int(float(s) * base) |
| 365 | |
| 366 | return int(size) |
| 367 | |
| 368 | |
| 369 | def strip_space(text, n): |
no outgoing calls
no test coverage detected
searching dependent graphs…