-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compression of data at the save to reduce the size of the file (#694
- Loading branch information
1 parent
047f722
commit 5722846
Showing
2 changed files
with
13 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import pickle | ||
import zlib | ||
|
||
|
||
def save(self, filename): | ||
serialized_data = pickle.dumps(self, protocol=5) | ||
compressed_data = zlib.compress(serialized_data) | ||
with open(filename, "wb") as file: | ||
pickle.dump(self, file) | ||
file.write(compressed_data) | ||
|
||
|
||
def load(filename): | ||
sm = None | ||
with open(filename, "rb") as file: | ||
sm = pickle.load(file) | ||
compressed_data = file.read() | ||
|
||
serialized_data = zlib.decompress(compressed_data) | ||
sm = pickle.loads(serialized_data) | ||
|
||
return sm |