diff --git a/lib/down/chunked_io.rb b/lib/down/chunked_io.rb index 938391b..9d82760 100644 --- a/lib/down/chunked_io.rb +++ b/lib/down/chunked_io.rb @@ -77,7 +77,7 @@ def read(length = nil, outbuf = nil) buffer.clear if buffer # deallocate string - data.force_encoding(@encoding) unless length + data.force_encoding(@encoding) data unless data.empty? && length && length > 0 end diff --git a/test/chunked_io_test.rb b/test/chunked_io_test.rb index 028acbe..c3d0d51 100644 --- a/test/chunked_io_test.rb +++ b/test/chunked_io_test.rb @@ -154,16 +154,16 @@ def chunked_io(**options) assert_equal "bc", io.read(2) end - it "returns content in binary encoding" do + it "returns content in requested encoding" do io = chunked_io(chunks: ["ab", "c"].each) assert_equal Encoding::BINARY, io.read(1).encoding io.rewind assert_equal Encoding::BINARY, io.read(1).encoding io = chunked_io(chunks: ["ab", "c"].each, encoding: "utf-8") - assert_equal Encoding::BINARY, io.read(1).encoding + assert_equal Encoding::UTF_8, io.read(1).encoding io.rewind - assert_equal Encoding::BINARY, io.read(1).encoding + assert_equal Encoding::UTF_8, io.read(1).encoding end end @@ -249,16 +249,16 @@ def chunked_io(**options) assert_equal "bc", io.read(2, "") end - it "returns content in binary encoding" do + it "returns content in requested encoding" do io = chunked_io(chunks: ["ab", "c"].each) assert_equal Encoding::BINARY, io.read(1, "").encoding io.rewind assert_equal Encoding::BINARY, io.read(1, "").encoding io = chunked_io(chunks: ["ab", "c"].each, encoding: "utf-8") - assert_equal Encoding::BINARY, io.read(1, "").encoding + assert_equal Encoding::UTF_8, io.read(1, "").encoding io.rewind - assert_equal Encoding::BINARY, io.read(1, "").encoding + assert_equal Encoding::UTF_8, io.read(1, "").encoding end end