Make HTTPIO compatible with multi-byte chars (Extracted from ChunkedIO)
This commit is contained in:
parent
c39ad568e4
commit
c91b64366a
|
@ -75,18 +75,28 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(length = nil)
|
def read(length = nil, outbuf = "")
|
||||||
out = ""
|
out = ""
|
||||||
|
|
||||||
until eof? || (length && out.length >= length)
|
length ||= size - tell
|
||||||
|
|
||||||
|
until length <= 0 || eof?
|
||||||
data = get_chunk
|
data = get_chunk
|
||||||
break if data.empty?
|
break if data.empty?
|
||||||
|
|
||||||
out << data
|
chunk_bytes = [BUFFER_SIZE - chunk_offset, length].min
|
||||||
@tell += data.bytesize
|
chunk_data = data.byteslice(0, chunk_bytes)
|
||||||
|
|
||||||
|
out << chunk_data
|
||||||
|
@tell += chunk_data.bytesize
|
||||||
|
length -= chunk_data.bytesize
|
||||||
end
|
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
|
out
|
||||||
end
|
end
|
||||||
|
@ -158,7 +168,7 @@ module Gitlab
|
||||||
# Provider: GCS
|
# 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 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
|
# - 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
|
end
|
||||||
|
|
||||||
@chunk[chunk_offset..BUFFER_SIZE]
|
@chunk[chunk_offset..BUFFER_SIZE]
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -44,10 +44,11 @@ module HttpIOHelpers
|
||||||
|
|
||||||
def remote_trace_body
|
def remote_trace_body
|
||||||
@remote_trace_body ||= File.read(expand_fixture_path('trace/sample_trace'))
|
@remote_trace_body ||= File.read(expand_fixture_path('trace/sample_trace'))
|
||||||
|
.force_encoding(Encoding::BINARY)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_trace_size
|
def remote_trace_size
|
||||||
remote_trace_body.length
|
remote_trace_body.bytesize
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_smaller_buffer_size_than(file_size)
|
def set_smaller_buffer_size_than(file_size)
|
||||||
|
|
Loading…
Reference in New Issue