From 84167afdf8a06874a4525ff1e892713e606be508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 19 May 2020 13:59:18 +0200 Subject: [PATCH 1/2] Fix flush methods to always flush underlying IO --- src/compress/deflate/writer.cr | 1 + src/pretty_print.cr | 2 ++ src/xml/builder.cr | 4 +++- src/yaml/builder.cr | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compress/deflate/writer.cr b/src/compress/deflate/writer.cr index b32a3af8b300..9652720cfdc9 100644 --- a/src/compress/deflate/writer.cr +++ b/src/compress/deflate/writer.cr @@ -60,6 +60,7 @@ class Compress::Deflate::Writer < IO return if @closed consume_output LibZ::Flush::SYNC_FLUSH + @output.flush end # Closes this writer. Must be invoked after all data has been written. diff --git a/src/pretty_print.cr b/src/pretty_print.cr index 0b32809504a5..7dbf4be6a7cf 100644 --- a/src/pretty_print.cr +++ b/src/pretty_print.cr @@ -191,6 +191,8 @@ class PrettyPrint end @buffer.clear @buffer_width = 0 + + @output.flush end private class Text diff --git a/src/xml/builder.cr b/src/xml/builder.cr index b5e30addcd97..44c8daa7f503 100644 --- a/src/xml/builder.cr +++ b/src/xml/builder.cr @@ -11,7 +11,7 @@ struct XML::Builder @box : Void* # Creates a builder that writes to the given *io*. - def initialize(io : IO) + def initialize(@io : IO) @box = Box.box(io) buffer = LibXML.xmlOutputBufferCreateIO( ->(ctx, buffer, len) { @@ -249,6 +249,8 @@ struct XML::Builder # this writer's `IO`. def flush call Flush + + @io.flush end # Sets the indent string. diff --git a/src/yaml/builder.cr b/src/yaml/builder.cr index c93cb8817091..cc925fc5a107 100644 --- a/src/yaml/builder.cr +++ b/src/yaml/builder.cr @@ -183,6 +183,8 @@ class YAML::Builder # Flushes any pending data to the underlying `IO`. def flush LibYAML.yaml_emitter_flush(@emitter) + + @io.flush end def finalize From ae232eb2d23404d3a078a6088b2b4a8926f5a832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 19 May 2020 14:09:49 +0200 Subject: [PATCH 2/2] fixup! Fix flush methods to always flush underlying IO --- src/xml/builder.cr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/xml/builder.cr b/src/xml/builder.cr index 44c8daa7f503..4597314ed99d 100644 --- a/src/xml/builder.cr +++ b/src/xml/builder.cr @@ -378,7 +378,6 @@ module XML # when StartDocument is omitted. xml.end_document xml.flush - io.flush v end end