diff options
Diffstat (limited to 'python/fatcat_tools/fcid.py')
-rw-r--r-- | python/fatcat_tools/fcid.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/python/fatcat_tools/fcid.py b/python/fatcat_tools/fcid.py index dd72b242..4194ea63 100644 --- a/python/fatcat_tools/fcid.py +++ b/python/fatcat_tools/fcid.py @@ -3,12 +3,18 @@ import base64 import uuid def fcid2uuid(s): + """ + Converts a fatcat identifier (base32 encoded string) to a uuid.UUID object + """ s = s.split('_')[-1].upper().encode('utf-8') assert len(s) == 26 raw = base64.b32decode(s + b"======") return str(uuid.UUID(bytes=raw)).lower() def uuid2fcid(s): + """ + Converts a uuid.UUID object to a fatcat identifier (base32 encoded string) + """ raw = uuid.UUID(s).bytes return base64.b32encode(raw)[:26].lower().decode('utf-8') |