diff options
Diffstat (limited to 'fietsboek/convert.py')
-rw-r--r-- | fietsboek/convert.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/fietsboek/convert.py b/fietsboek/convert.py index 3c8208b..d3bfb22 100644 --- a/fietsboek/convert.py +++ b/fietsboek/convert.py @@ -49,4 +49,20 @@ def from_fit(data: bytes) -> GPX: return gpx -__all__ = ["from_fit"] +def smart_convert(data: bytes) -> bytes: + """Tries to be smart in converting the input bytes. + + This function automatically applies the correct conversion if possible. + + Note that this function is not guaranteed to return valid GPX bytes. In the worst case, + invalid bytes are simply passed through. + + :param data: The input bytes. + :return: The converted content. + """ + if len(data) > 11 and data[9:12] == b"FIT": + return from_fit(data).to_xml().encode("utf-8") + return data + + +__all__ = ["from_fit", "smart_convert"] |