Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change Log

### v0.3.5

- Fix the issue that StreamWriter will read more bytes than wanted

### v0.3.4

- Fix handling gzip/deflate response
Expand Down
9 changes: 7 additions & 2 deletions lib/aliyun/oss/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ def read(bytes = nil, outbuf = nil)
ret = ""
loop do
if bytes
ret << @buffer.slice!(0, bytes)
break if ret.size >= bytes
fail if bytes < 0
piece = @buffer.slice!(0, bytes)
if piece
ret << piece
bytes -= piece.size
break if bytes == 0
end
else
ret << @buffer
@buffer.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/aliyun/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Aliyun

VERSION = "0.3.4"
VERSION = "0.3.5"

end # Aliyun
18 changes: 18 additions & 0 deletions spec/aliyun/oss/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ module OSS
r = s.read
expect(r).to eq('')
end

it "should read exactly bytes" do
s = HTTP::StreamWriter.new do |sr|
100.times { sr << 'x' * 10 }
end

r = s.read(11)
expect(r.size).to eq(11)

r = s.read(25)
expect(r.size).to eq(25)

r = s.read(900)
expect(r.size).to eq(900)

r = s.read(1000)
expect(r.size).to eq(64)
end
end # StreamWriter

end # HTTP
Expand Down