abrignoni / abrignoni/iLEAPP

feature: binary file safe access

Aperta
#1,286 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
1.2k
Fork
303
Merge medio
4h 32m
PR unite (30g)
216

Descrizione

create a safe access function for modules to use that allows for reading binary data from the file.

here is a possible snippet as a `contextmanager` function that allows `with` usage
``` python
@contextmanager
def open_file_binary(file_path):
"""Context manager to safely open a file for binary reading."""
try:
with open(file_path, 'rb') as f:
yield f
except (FileNotFoundError, PermissionError, OSError) as e:
logfunc(f"Error accessing file {file_path}: {e}")
yield None
```

allows the module to use `with` in that code:
``` python
with open_file_binary(file_path) as file:
if file is None:
continue
data = struct.unpack('

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.