Merge pull request 'feature/load_compressed_city' (#46) from feature/load_compressed_city into main
Reviewed-on: https://nextgenerations-cities.encs.concordia.ca/gitea/CERC/hub/pulls/46
This commit is contained in:
commit
bb05b01312
@ -14,6 +14,7 @@ import math
|
||||
import pickle
|
||||
import sys
|
||||
import pathlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import List, Union
|
||||
|
||||
@ -299,6 +300,20 @@ class City:
|
||||
with open(city_filename, 'rb') as file:
|
||||
return pickle.load(file)
|
||||
|
||||
@staticmethod
|
||||
def load_compressed(compressed_city_filename, destination_filename) -> City:
|
||||
"""
|
||||
Load a city from compressed_city_filename
|
||||
:param compressed_city_filename: Compressed pickle as source
|
||||
:param destination_filename: 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()))
|
||||
loaded_city = City.load(destination_filename)
|
||||
os.unlink(destination_filename)
|
||||
return loaded_city
|
||||
|
||||
def save(self, city_filename):
|
||||
"""
|
||||
Save a city into the given filename
|
||||
|
Loading…
Reference in New Issue
Block a user