Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg committed Nov 12, 2023
1 parent cd6cf0d commit 0b1a1df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,15 @@ public static ArrayPointer<CCharPointer> saveNetworkToBinaryBuffer(IsolateThread
Reporter reporter = ReportCUtils.getReporter(reporterHandle);
// to support all kind of export: simple file or multiple to an archive,
// best is to write to a zip file
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bos)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(bos)) {
DataSource dataSource = new ZipMemDataSource("file", zos);
exporter.export(network, parameters, dataSource, reporter);
bos.flush();
byte[] bytes = bos.toByteArray();
return Util.createByteArray(bytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
byte[] bytes = bos.toByteArray();
return Util.createByteArray(bytes);
});
}

Expand Down
2 changes: 2 additions & 0 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def save_to_string(self, format: str = 'XIIDM', parameters: ParamsDict = None, r
def save_to_binary_buffer(self, format: str = 'XIIDM', parameters: ParamsDict = None, reporter: Reporter = None) -> io.BytesIO:
"""
Save a network to a binary buffer using a specified format.
In the current implementation, whatever the specified format is (so a format creating a single file or a format
creating multiple files), the created binary buffer is a zip file.
Args:
format: format to export, only support mono file type, defaults to 'XIIDM'
Expand Down
3 changes: 2 additions & 1 deletion tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def test_save_cgmes_zip():
n = pp.network.create_eurostag_tutorial_example1_network()
buffer = n.save_to_binary_buffer(format='CGMES')
with zipfile.ZipFile(buffer, 'r') as zip_file:
assert [''] == zip_file.namelist()
assert ['file_EQ.xml', 'file_TP.xml', 'file_SSH.xml', 'file_SV.xml'] == zip_file.namelist()


def test_load_zipped_xiidm():
with open(DATA_DIR.joinpath('battery_xiidm.zip'), "rb") as fh:
Expand Down

0 comments on commit 0b1a1df

Please sign in to comment.