aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2025-02-20 19:11:22 +0000
committerAlex Schofield <git@ajschof.me>2025-02-20 19:11:22 +0000
commitff3a5630fe5440f61fffc2b2732ba38fad2b67a7 (patch)
treed24bae78c95bc08859fc96b3262d5da3e72c1c2f
parent21e5b8fdd204f9d1ca8549fa512fe825760e9366 (diff)
downloadgdpr-obfuscator-ff3a5630fe5440f61fffc2b2732ba38fad2b67a7.tar.gz
gdpr-obfuscator-ff3a5630fe5440f61fffc2b2732ba38fad2b67a7.zip
move create_byte_stream() to utils.py
-rw-r--r--gdpr_obfuscator/utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/gdpr_obfuscator/utils.py b/gdpr_obfuscator/utils.py
index 740db90..2dffbc2 100644
--- a/gdpr_obfuscator/utils.py
+++ b/gdpr_obfuscator/utils.py
@@ -1,5 +1,8 @@
# Utility functions
from .logger import get_logger
+from typing import List, Dict
+import csv
+import io
class Utilities:
@@ -14,3 +17,20 @@ class Utilities:
key = "/".join(parts)
self.logger.debug(f"Key: {key}")
return bucket, key
+
+ def create_byte_stream(self, data: List[Dict[str, str]]) -> bytes:
+ if not data:
+ self.logger.error("Invalid or empty data was provided to write")
+ return b""
+
+ output = io.StringIO()
+
+ headers = list(data[0].keys())
+
+ writer = csv.DictWriter(output, fieldnames=headers)
+ writer.writeheader()
+ writer.writerows(data)
+
+ csv_string = output.getvalue()
+
+ return csv_string.encode("utf-8")
git.ajschof.me — hosted by ajschofield — powered by cgit