Determine if an existing file is gzipped based on magic bytes, not suffix
This commit is contained in:
parent
03a359e446
commit
ce5d386a24
4 changed files with 17 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ import gdsii.structure
|
|||
import gdsii.elements
|
||||
|
||||
from .utils import mangle_name, make_dose_table, dose2dtype, dtype2dose, clean_pattern_vertices
|
||||
from .utils import is_gzipped
|
||||
from .. import Pattern, SubPattern, PatternError, Label, Shape
|
||||
from ..shapes import Polygon, Path
|
||||
from ..repetition import Grid
|
||||
|
|
@ -190,7 +191,7 @@ def readfile(filename: Union[str, pathlib.Path],
|
|||
"""
|
||||
Wrapper for `masque.file.gdsii.read()` that takes a filename or path instead of a stream.
|
||||
|
||||
Will automatically decompress files with a .gz suffix.
|
||||
Will automatically decompress gzipped files.
|
||||
|
||||
Args:
|
||||
filename: Filename to save to.
|
||||
|
|
@ -198,7 +199,7 @@ def readfile(filename: Union[str, pathlib.Path],
|
|||
**kwargs: passed to `masque.file.gdsii.read`
|
||||
"""
|
||||
path = pathlib.Path(filename)
|
||||
if path.suffix == '.gz':
|
||||
if is_gzipped(path):
|
||||
open_func: Callable = gzip.open
|
||||
else:
|
||||
open_func = open
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue