Function
load_file
(
path: Union[str, Path],
*,
content_type: str = None,
encoding: str = 'utf8',
proto: Protocol = None,
allow_pickle: bool = False,
json_loads: Callable[[str], Any] = json.loads,
)
Source from the content-addressed store, hash-verified
| 45 | |
| 46 | |
| 47 | def load_file( |
| 48 | path: Union[str, Path], |
| 49 | *, |
| 50 | content_type: str = None, |
| 51 | encoding: str = 'utf8', |
| 52 | proto: Protocol = None, |
| 53 | allow_pickle: bool = False, |
| 54 | json_loads: Callable[[str], Any] = json.loads, |
| 55 | ) -> Any: |
| 56 | path = Path(path) |
| 57 | b = path.read_bytes() |
| 58 | if content_type is None: |
| 59 | if path.suffix in ('.js', '.json'): |
| 60 | proto = Protocol.json |
| 61 | elif path.suffix == '.pkl': |
| 62 | proto = Protocol.pickle |
| 63 | |
| 64 | return load_str_bytes( |
| 65 | b, proto=proto, content_type=content_type, encoding=encoding, allow_pickle=allow_pickle, json_loads=json_loads |
| 66 | ) |