Beispiel #1
0
    def __init__(self, fileish, check_crc=True, data_processor=None):
        if hasattr(fileish, 'read'):
            # BytesIO-like object
            self._file = fileish
        elif isinstance(fileish, str):
            # Python2 - file path, file contents in the case of a TypeError
            # Python3 - file path
            try:
                self._file = open(fileish, 'rb')
            except TypeError:
                self._file = io.BytesIO(fileish)
        else:
            # Python 3 - file contents
            self._file = io.BytesIO(fileish)

        self.check_crc = check_crc
        self._processor = data_processor or FitFileDataProcessor()

        # Get total filesize
        self._file.seek(0, os.SEEK_END)
        self._filesize = self._file.tell()
        self._file.seek(0, os.SEEK_SET)

        # Start off by parsing the file header (sets initial attribute values)
        self._parse_file_header()
Beispiel #2
0
    def __init__(self, fileish, check_crc=True, data_processor=None):
        if hasattr(fileish, 'read'):
            self._file = fileish
        else:
            self._file = open(fileish, "rb")

        self.check_crc = check_crc

        self._accumulators = {}
        self._bytes_left = -1  # Not valid until after _parse_file_header()

        self._digest = hashlib.sha256(self._file.read()).hexdigest()
        self._file_size = self._file.tell()  # Get End_Position
        self._file.seek(0, 0)  # "Rewind" file

        self._complete = False
        self._compressed_ts_accumulator = 0
        self._crc = 0
        self._local_mesgs = {}
        self._messages = []
        self._processor = data_processor or FitFileDataProcessor()
        self._files = [0]

        while self._files[-1] <= self._file_size:
            pos = self._parse_file_header()

            if self._files[-1] + pos == self._file_size:
                break
            self._file.seek(self._files[-1] + pos)
            self._files.append(self._files[-1] + pos)

        for i in range(len(self._files)):
            self.select_fit_subfile(i)
            self.parse()
Beispiel #3
0
    def __init__(self, fileish, check_crc=True, data_processor=None):
        if hasattr(fileish, 'read'):
            self._file = fileish
        else:
            try:
                self._file = open(fileish, 'rb')
            except:
                # If the header smells like a string containing a fit file's
                # data, we wrap it with StringIO
                if isinstance(fileish, str) and fileish[8:12] == '.FIT':
                    self._file = io.StringIO(fileish)
                else:
                    raise

        self.check_crc = check_crc

        self._accumulators = {}
        self._bytes_left = -1  # Not valid until after _parse_file_header()
        self._complete = False
        self._compressed_ts_accumulator = 0
        self._crc = 0
        self._local_mesgs = {}
        self._messages = []
        self._processor = data_processor or FitFileDataProcessor()

        # Start off by parsing the file header (makes self._bytes_left valid)
        self._parse_file_header()
Beispiel #4
0
    def __init__(self, fileish, check_crc=True, data_processor=None):
        self._file = fileish_open(fileish, 'rb')

        self.check_crc = check_crc
        self._crc = None
        self._processor = data_processor or FitFileDataProcessor()

        # Get total filesize
        self._file.seek(0, os.SEEK_END)
        self._filesize = self._file.tell()
        self._file.seek(0, os.SEEK_SET)

        # Start off by parsing the file header (sets initial attribute values)
        self._parse_file_header()
Beispiel #5
0
    def __init__(self, fileish, check_crc=True, data_processor=None):
        if hasattr(fileish, 'read'):
            self._file = fileish
        elif isinstance(fileish, bytes) and fileish[8:12] == b'.FIT':
            self._file = io.BytesIO(fileish)
        else:
            self._file = open(fileish, 'rb')

        self.check_crc = check_crc
        self._processor = data_processor or FitFileDataProcessor()

        # Get total filesize
        self._file.seek(0, os.SEEK_END)
        self._filesize = self._file.tell()
        self._file.seek(0, os.SEEK_SET)

        # Start off by parsing the file header (sets initial attribute values)
        self._parse_file_header()
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     self._processor = kwargs.pop("data_processor", None) or FitFileDataProcessor()
     super(DataProcessorMixin, self).__init__(*args, **kwargs)