Skip to content

Commit

Permalink
close TranscodingStream with stop_on_end set (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 authored Mar 18, 2024
1 parent da618b2 commit c3e84d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 4 additions & 9 deletions src/write_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c3e84d6

Please sign in to comment.