Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass string instead of Path object to open #37

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
This function is closely following the load_xdf reference implementation.
"""

import os
import struct
import itertools
import gzip
Expand Down Expand Up @@ -198,7 +197,8 @@ def load_xdf(filename,
"""

logger.info('Importing XDF file %s...' % filename)
if not os.path.exists(filename):
filename = Path(filename).resolve() # absolute path following symlinks
if not filename.exists():
raise Exception('file %s does not exist.' % filename)

# if select_streams is an int or a list of int, load only streams
Expand All @@ -225,7 +225,7 @@ def load_xdf(filename,
# XML content of the file header chunk
fileheader = None
# number of bytes in the file for fault tolerance
filesize = os.path.getsize(filename)
filesize = filename.stat().st_size

with open_xdf(filename) as f:
# for each chunk
Expand Down Expand Up @@ -364,11 +364,11 @@ def load_xdf(filename,

def open_xdf(filename):
"""Open XDF file for reading."""
filename = Path(filename) # convert to pathlib object
filename = Path(filename) # ensure convert to pathlib object
if filename.suffix == '.xdfz' or filename.suffixes == ['.xdf', '.gz']:
f = gzip.open(filename, 'rb')
f = gzip.open(str(filename), 'rb')
else:
f = open(filename, 'rb')
f = open(str(filename), 'rb')
if f.read(4) != b'XDF:': # magic bytes
raise IOError('Invalid XDF file {}'.format(filename))
return f
Expand Down