From c57f265da5d8e5aec90c6c7635fd8c77641a81e5 Mon Sep 17 00:00:00 2001
From: morkolai <nikolai-mork@live.no>
Date: Thu, 19 Mar 2020 18:22:04 +0100
Subject: [PATCH] #69 Oppdatert input og output til funksjoner

---
 soitool/compressor.py | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/soitool/compressor.py b/soitool/compressor.py
index 4152087..2fd8ff2 100644
--- a/soitool/compressor.py
+++ b/soitool/compressor.py
@@ -1,48 +1,48 @@
 import lzma
 import json
+import codecs
 
 
-def compress(file):
+def compress(soi):
     """
-    Compress a file using lzma.
+    Compress a soi using lzma.
 
     Parameters
     ----------
-    file : string
-        The file to compress
+    soi : dict
+        soi as dict to be compresesed
 
     Returns
     -------
     string
-        The compressed file
+        The compressed soi as a str
     """
-    file = file.encode(encoding="ascii")
-    return str(lzma.compress(file))
+    soi = json.dumps(soi)
+    soi = soi.encode(encoding="ascii")
+    return str(lzma.compress(soi))
 
 
-def decompress(file, return_obj=True):
+def decompress(file):
     """
-    Decompress to either object or string.
+    Decompress to python dict.
 
     Parameters
     ----------
     file : string
         The string of the compressed object
-    return_obj : bool, optional
-        True if return as python object, by default True
 
     Returns
     -------
-    python object or string
-        The decompressed file as object or string
+    dict
+        The decompressed file as dict
     """
     # Removes extra b' notation
     file = file[2:-1].encode(encoding="ascii")
+    # Remove double //
+    file = codecs.escape_decode(file, "hex")
+    # Compresses
     file = lzma.decompress(file[0])
     # Cast to ascii string
     file = file.decode(encoding="ascii")
-    if return_obj:
-        # Return as python object
-        return json.loads(file)
-
-    return file
+    # Return as python datastructure
+    return json.loads(file)
-- 
GitLab