Prevent dups when using StringIO for binary reads
This commit is contained in:
parent
bf934a8f7c
commit
d704f0c4a0
|
@ -336,6 +336,12 @@ module Gitlab
|
||||||
s.dup.force_encoding(Encoding::ASCII_8BIT)
|
s.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.binary_stringio(s)
|
||||||
|
io = StringIO.new(s || '')
|
||||||
|
io.set_encoding(Encoding::ASCII_8BIT)
|
||||||
|
io
|
||||||
|
end
|
||||||
|
|
||||||
def self.encode_repeated(a)
|
def self.encode_repeated(a)
|
||||||
Google::Protobuf::RepeatedField.new(:bytes, a.map { |s| self.encode(s) } )
|
Google::Protobuf::RepeatedField.new(:bytes, a.map { |s| self.encode(s) } )
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,12 +18,11 @@ module Gitlab
|
||||||
commit_details: gitaly_commit_details(commit_details)
|
commit_details: gitaly_commit_details(commit_details)
|
||||||
)
|
)
|
||||||
|
|
||||||
strio = StringIO.new(content)
|
strio = GitalyClient.binary_stringio(content)
|
||||||
|
|
||||||
enum = Enumerator.new do |y|
|
enum = Enumerator.new do |y|
|
||||||
until strio.eof?
|
until strio.eof?
|
||||||
chunk = strio.read(MAX_MSG_SIZE)
|
request.content = strio.read(MAX_MSG_SIZE)
|
||||||
request.content = GitalyClient.encode(chunk)
|
|
||||||
|
|
||||||
y.yield request
|
y.yield request
|
||||||
|
|
||||||
|
@ -46,12 +45,11 @@ module Gitlab
|
||||||
commit_details: gitaly_commit_details(commit_details)
|
commit_details: gitaly_commit_details(commit_details)
|
||||||
)
|
)
|
||||||
|
|
||||||
strio = StringIO.new(content)
|
strio = GitalyClient.binary_stringio(content)
|
||||||
|
|
||||||
enum = Enumerator.new do |y|
|
enum = Enumerator.new do |y|
|
||||||
until strio.eof?
|
until strio.eof?
|
||||||
chunk = strio.read(MAX_MSG_SIZE)
|
request.content = strio.read(MAX_MSG_SIZE)
|
||||||
request.content = GitalyClient.encode(chunk)
|
|
||||||
|
|
||||||
y.yield request
|
y.yield request
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue