Commit d704f0c4 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Prevent dups when using StringIO for binary reads

parent bf934a8f
......@@ -336,6 +336,12 @@ module Gitlab
s.dup.force_encoding(Encoding::ASCII_8BIT)
end
def self.binary_stringio(s)
io = StringIO.new(s || '')
io.set_encoding(Encoding::ASCII_8BIT)
io
end
def self.encode_repeated(a)
Google::Protobuf::RepeatedField.new(:bytes, a.map { |s| self.encode(s) } )
end
......
......@@ -18,12 +18,11 @@ module Gitlab
commit_details: gitaly_commit_details(commit_details)
)
strio = StringIO.new(content)
strio = GitalyClient.binary_stringio(content)
enum = Enumerator.new do |y|
until strio.eof?
chunk = strio.read(MAX_MSG_SIZE)
request.content = GitalyClient.encode(chunk)
request.content = strio.read(MAX_MSG_SIZE)
y.yield request
......@@ -46,12 +45,11 @@ module Gitlab
commit_details: gitaly_commit_details(commit_details)
)
strio = StringIO.new(content)
strio = GitalyClient.binary_stringio(content)
enum = Enumerator.new do |y|
until strio.eof?
chunk = strio.read(MAX_MSG_SIZE)
request.content = GitalyClient.encode(chunk)
request.content = strio.read(MAX_MSG_SIZE)
y.yield request
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment