Coverage for domain / model / file.py: 100.00%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-07 00:07 +0000

1"""File model for representing files in the conversion system.""" 

2from dataclasses import dataclass 

3from typing import Any 

4 

5 

6@dataclass 

7class File: 

8 """Pure data model representing a file's metadata. 

9 

10 This dataclass intentionally does not perform filesystem IO. Use an 

11 adapter or factory in the infra layer (for example, 

12 `domain.adapters.file_factories.file_from_path`) to construct `File` 

13 instances from concrete filesystem paths. 

14 """ 

15 

16 name: str 

17 size_bytes: int 

18 

19 @staticmethod 

20 def format_file_size(size_bytes: int) -> str: 

21 size = float(size_bytes) 

22 for unit in ['B', 'KB', 'MB', 'GB']: 

23 if size < 1024.0: 

24 if unit == 'B': 

25 return f"{int(size)}{unit}" 

26 return f"{size:.1f}{unit}" 

27 size /= 1024.0 

28 return f"{size:.1f}TB" 

29 

30 @property 

31 def formatted_size(self) -> str: 

32 return self.format_file_size(self.size_bytes) 

33 

34 def to_dict(self) -> dict: 

35 return { 

36 'name': self.name, 

37 'size': self.formatted_size 

38 }