Skip to content

Commit

Permalink
Merge pull request #58 from adamreeve/revert-57-master
Browse files Browse the repository at this point in the history
Revert "Allow TdmsFile to accept any file-like object"
  • Loading branch information
adamreeve committed Jan 29, 2017
2 parents c396458 + be50a82 commit 58d789b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions nptdms/tdms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
from datetime import datetime, timedelta
import tempfile
from io import BytesIO
try:
import pytz
except ImportError:
Expand Down Expand Up @@ -92,17 +93,14 @@


def fromfile(file, dtype, count, *args, **kwargs):
"""Wrapper around np.fromfile to support any file-like object"""
""" Wrapper around np.fromfile to support BytesIO fake files."""

if isinstance(file, int) or (
hasattr(file, 'fileno') and callable(file.fileno)):
# satisfy criteria that 'argument must be an int, or
# have a fileno() method' - from numpy TypeError
return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs)
else:
return np.frombuffer(
if isinstance(file, BytesIO):
return np.fromstring(
file.read(count * np.dtype(dtype).itemsize),
dtype=dtype, count=count, *args, **kwargs)
else:
return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs)


def read_string(file):
Expand Down

0 comments on commit 58d789b

Please sign in to comment.