@@ -44,18 +44,7 @@ def save_model(model: GeoModel, path: str | None = None, validate_serialization:
44
44
# If no extension, add the valid extension
45
45
path = str (path_obj ) + VALID_EXTENSION
46
46
47
- model_json = model .model_dump_json (by_alias = True , indent = 4 )
48
-
49
- # Compress the binary data
50
- zlib = require_zlib ()
51
- compressed_binary_input = zlib .compress (model .structural_frame .input_tables_binary )
52
- compressed_binary_grid = zlib .compress (model .grid .grid_binary )
53
-
54
- binary_file = _to_binary (
55
- header_json = model_json ,
56
- body_input = compressed_binary_input ,
57
- body_grid = compressed_binary_grid
58
- )
47
+ binary_file = model_to_binary (model )
59
48
60
49
if validate_serialization :
61
50
model_deserialized = _deserialize_binary_file (binary_file )
@@ -72,6 +61,20 @@ def save_model(model: GeoModel, path: str | None = None, validate_serialization:
72
61
return path # Return the actual path used (helpful if extension was added)
73
62
74
63
64
+ def model_to_binary (model : GeoModel ) -> bytes :
65
+ model_json = model .model_dump_json (by_alias = True , indent = 4 )
66
+ # Compress the binary data
67
+ zlib = require_zlib ()
68
+ compressed_binary_input = zlib .compress (model .structural_frame .input_tables_binary )
69
+ compressed_binary_grid = zlib .compress (model .grid .grid_binary )
70
+ binary_file = _to_binary (
71
+ header_json = model_json ,
72
+ body_input = compressed_binary_input ,
73
+ body_grid = compressed_binary_grid
74
+ )
75
+ return binary_file
76
+
77
+
75
78
def load_model (path : str ) -> GeoModel :
76
79
"""
77
80
Load a GeoModel from a file with extension validation.
0 commit comments