From 70cc659c147198c2555246f6af737c4eb019e25a Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Tue, 12 Sep 2023 14:57:13 -0400 Subject: [PATCH] Add load_compressed function to city.py --- hub/city_model_structure/city.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 567b1937..37c8d30e 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -299,6 +299,21 @@ class City: with open(city_filename, 'rb') as file: return pickle.load(file) + @staticmethod + def load_compressed(compressed_city_filename, destination_filename) -> City: + """ + Load the pickle file name in the current city + :param source_file: Compressed pickle as source + :param destination_file: Pickle file as destination + :return: City + """ + with open(str(compressed_city_filename), 'rb') as source, open(str(destination_filename), 'wb') as destination: + destination.write(bz2.decompress(source.read())) + return City.load(destination_filename) + + @staticmethod + def load_compressed(city_filename, ): + def save(self, city_filename): """ Save a city into the given filename