From 46b03668ce29e12765cd1145f61f3c0e060111ee Mon Sep 17 00:00:00 2001 From: nhz2 Date: Mon, 18 Mar 2024 16:57:27 -0400 Subject: [PATCH] close TranscodingStream with stop_on_end set --- Project.toml | 2 +- src/write_data.jl | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 454ccc92..1ac5234a 100644 --- a/Project.toml +++ b/Project.toml @@ -15,6 +15,6 @@ VTKBase = "4004b06d-e244-455f-a6ce-a5f9919cc534" CodecZlib = "0.7" FillArrays = "0.13, 1.0" LightXML = "0.9" -TranscodingStreams = "0.9, 0.10" +TranscodingStreams = "0.10.5" VTKBase = "1.0" julia = "1.6" diff --git a/src/write_data.jl b/src/write_data.jl index a9dfc9fb..5b2fe9d3 100644 --- a/src/write_data.jl +++ b/src/write_data.jl @@ -230,11 +230,10 @@ function data_to_xml_appended(vtk::DatasetFile, xDA::XMLElement, data) end # Write compressed data. - zWriter = ZlibCompressorStream(buf, level=vtk.compression_level) + zWriter = ZlibCompressorStream(buf, level=vtk.compression_level, stop_on_end=true) write_array(zWriter, data) write(zWriter, TranscodingStreams.TOKEN_END) - flush(zWriter) - TranscodingStreams.finalize(zWriter.codec) # Release allocated resources (issue #43) + close(zWriter) # Release allocated resources (issue #43) # Go back to `initpos` and write real header. endpos = position(buf) @@ -276,13 +275,12 @@ function data_to_xml_inline(vtk::DatasetFile, xDA::XMLElement, data) # base64-encoded separately!! # That's why we don't use a single buffer that contains both, like in the # other data_to_xml function. - local zWriter if compress # Write compressed data. - zWriter = ZlibCompressorStream(buf, level=vtk.compression_level) + zWriter = ZlibCompressorStream(buf, level=vtk.compression_level, stop_on_end=true) write_array(zWriter, data) write(zWriter, TranscodingStreams.TOKEN_END) - flush(zWriter) + close(zWriter) else write_array(buf, data) end @@ -297,9 +295,6 @@ function data_to_xml_inline(vtk::DatasetFile, xDA::XMLElement, data) add_text(xDA, base64encode(take!(buf))) add_text(xDA, "\n") - if compress - close(zWriter) - end close(buf) xDA