-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquashpickle.py
More file actions
78 lines (69 loc) · 1.41 KB
/
squashpickle.py
File metadata and controls
78 lines (69 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Module providing a pickle-like interface with compression."""
import gzip
import pickle
def dumps(
obj,
protocol=None,
*,
fix_imports=True,
buffer_callback=None,
):
"""Serialise the object and return the result."""
return gzip.compress(
pickle.dumps(
obj,
protocol=protocol,
fix_imports=fix_imports,
buffer_callback=buffer_callback,
)
)
def dump(
obj,
file,
protocol=None,
*,
fix_imports=True,
buffer_callback=None,
):
"""Serialise the object to a file."""
file.write(
dumps(
obj,
protocol=protocol,
fix_imports=fix_imports,
buffer_callback=buffer_callback,
)
)
def loads(
data,
/,
*,
fix_imports=True,
encoding="ASCII",
errors="strict",
buffers=(),
):
"""Deserialize the object and return the result."""
return pickle.loads(
gzip.decompress(data),
fix_imports=fix_imports,
encoding=encoding,
errors=errors,
buffers=buffers,
)
def load(
file,
*,
fix_imports=True,
encoding="ASCII",
errors="strict",
buffers=(),
):
"""Deserialize the object from file and return the result."""
return loads(
file.read(),
fix_imports=fix_imports,
encoding=encoding,
errors=errors,
buffers=buffers,
)