Skip to content

Commit

Permalink
Flate: try to inflate even if @stream.avail_in is 0 (#4193)
Browse files Browse the repository at this point in the history
Fix #4192

Probably LibZ::Error::STREAM_END is only way to detect the end of a stream.
  • Loading branch information
makenowjust authored and bcardiff committed Mar 27, 2017
1 parent 3c74890 commit 6a45e08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/std/flate/flate_spec.cr
Expand Up @@ -2,6 +2,26 @@ require "spec"
require "flate"

module Flate
describe Reader do
it "should read byte by byte (#4192)" do
io = IO::Memory.new
"cbc9cc4b350402ae1c20c30808b800".scan(/../).each do |match|
io.write_byte match[0].to_u8(16)
end
io.rewind

reader = Reader.new(io)

str = String::Builder.build do |builder|
while b = reader.read_byte
builder.write_byte b
end
end

str.should eq("line1111\nline2222\n")
end
end

describe Writer do
it "should be able to write" do
message = "this is a test string !!!!\n"
Expand Down
1 change: 0 additions & 1 deletion src/flate/reader.cr
Expand Up @@ -77,7 +77,6 @@ class Flate::Reader
@stream.next_in = @buf.to_unsafe
@stream.avail_in = @io.read(@buf.to_slice).to_u32
end
return 0 if @stream.avail_in == 0
end

old_avail_in = @stream.avail_in
Expand Down

0 comments on commit 6a45e08

Please sign in to comment.