Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-04-17 08:50:32 +0300
committerShinya Maeda <shinya@gitlab.com>2018-04-17 08:50:32 +0300
commitc91b64366ae3d1a095661057a936f1b445926b19 (patch)
tree26a01d6f415bcb86b3a7aa10da62cf17211a82ec /lib/gitlab/ci/trace
parentc39ad568e469b288a510c03b1aebefd78d8a9ee5 (diff)
Make HTTPIO compatible with multi-byte chars (Extracted from ChunkedIO)
Diffstat (limited to 'lib/gitlab/ci/trace')
-rw-r--r--lib/gitlab/ci/trace/http_io.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/gitlab/ci/trace/http_io.rb b/lib/gitlab/ci/trace/http_io.rb
index ac4308f4e2c..cff924e27ef 100644
--- a/lib/gitlab/ci/trace/http_io.rb
+++ b/lib/gitlab/ci/trace/http_io.rb
@@ -75,18 +75,28 @@ module Gitlab
end
end
- def read(length = nil)
+ def read(length = nil, outbuf = "")
out = ""
- until eof? || (length && out.length >= length)
+ length ||= size - tell
+
+ until length <= 0 || eof?
data = get_chunk
break if data.empty?
- out << data
- @tell += data.bytesize
+ chunk_bytes = [BUFFER_SIZE - chunk_offset, length].min
+ chunk_data = data.byteslice(0, chunk_bytes)
+
+ out << chunk_data
+ @tell += chunk_data.bytesize
+ length -= chunk_data.bytesize
end
- out = out[0, length] if length && out.length > length
+ # If outbuf is passed, we put the output into the buffer. This supports IO.copy_stream functionality
+ if outbuf
+ outbuf.slice!(0, outbuf.bytesize)
+ outbuf << out
+ end
out
end
@@ -158,7 +168,7 @@ module Gitlab
# Provider: GCS
# - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206
# - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPOK 200
- @chunk_range ||= (chunk_start...(chunk_start + @chunk.length))
+ @chunk_range ||= (chunk_start...(chunk_start + @chunk.bytesize))
end
@chunk[chunk_offset..BUFFER_SIZE]