Commit 4f41e2a1 authored by Luciano Cauzzi's avatar Luciano Cauzzi

added encoding method

parent d292a732
......@@ -6,6 +6,7 @@ import ntpath
import hashlib
import zipfile
import zlib
from typing import Optional
from logger_library import Logger
......@@ -220,3 +221,25 @@ def rename(src, dest) -> bool:
print("[FILESYSTEM]: Error while renaming file \n{}".format(e))
return False
return True
def save_file_from_base64(content: str, file_name: str, destination_path: str) -> bool:
try:
file_content = base64.b64decode("{}".format(content))
file_destination_path = "{}/{}".format(destination_path, file_name)
with open(file_destination_path, "wb") as f:
f.write(file_content)
except Exception as e:
logger.error("[ERROR]: error while decoding file from base64" + str(e))
return False
return True
def encode_file_base64(file_name: str) -> Optional[str]:
try:
with open(file_name, "rb") as f:
encoded_file = base64.b64encode(f.read())
return encoded_file
except Exception as e:
logger.error("[ERROR]: error while encoding fil to base64" + str(e))
return None
......@@ -3,7 +3,7 @@ import setuptools
setup(
name='file_manager',
version='0.1.15',
version='0.1.16',
packages=setuptools.find_packages(),
dependency_links=['http://github.comune.brescia.it/innovation-that-excites/logger_library#egg=logger_library'],
install_requires=['setuptools', 'logger_library'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment