Align force_encoding strategy into Trace::Stream
This commit is contained in:
parent
731118d349
commit
1e817e0018
|
|
@ -28,7 +28,7 @@ module Ci
|
|||
raw_data
|
||||
else
|
||||
raise 'Unsupported data store'
|
||||
end&.force_encoding(Encoding::BINARY)
|
||||
end&.force_encoding(Encoding::BINARY) # Redis/Database return UTF-8 string as default
|
||||
end
|
||||
|
||||
def set_data(value)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def append(data, offset)
|
||||
write do |stream|
|
||||
write('a+b') do |stream|
|
||||
current_length = stream.size
|
||||
return -current_length unless current_length == offset
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ module Gitlab
|
|||
stream&.close
|
||||
end
|
||||
|
||||
def write(mode = 'a+b')
|
||||
def write(mode)
|
||||
stream = Gitlab::Ci::Trace::Stream.new do
|
||||
if current_path
|
||||
File.open(current_path, mode)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ module Gitlab
|
|||
|
||||
def write(data)
|
||||
start_pos = tell
|
||||
data = data.force_encoding(Encoding::BINARY)
|
||||
|
||||
while tell < start_pos + data.bytesize
|
||||
# get slice from current offset till the end where it falls into chunk
|
||||
|
|
@ -178,7 +177,7 @@ module Gitlab
|
|||
current_chunk.tap do |chunk|
|
||||
raise FailedToGetChunkError unless chunk
|
||||
|
||||
@chunk = chunk.data.force_encoding(Encoding::BINARY)
|
||||
@chunk = chunk.data
|
||||
@chunk_range = chunk.range
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
def append(data, offset)
|
||||
data = data.force_encoding(Encoding::BINARY)
|
||||
|
||||
stream.truncate(offset)
|
||||
stream.seek(0, IO::SEEK_END)
|
||||
stream.write(data)
|
||||
|
|
@ -44,6 +46,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
def set(data)
|
||||
data = data.force_encoding(Encoding::BINARY)
|
||||
|
||||
stream.seek(0, IO::SEEK_SET)
|
||||
stream.write(data)
|
||||
stream.truncate(data.bytesize)
|
||||
|
|
@ -126,11 +130,11 @@ module Gitlab
|
|||
buf += debris
|
||||
debris, *lines = buf.each_line.to_a
|
||||
lines.reverse_each do |line|
|
||||
yield(line.force_encoding('UTF-8'))
|
||||
yield(line.force_encoding(Encoding.default_external))
|
||||
end
|
||||
end
|
||||
|
||||
yield(debris.force_encoding('UTF-8')) unless debris.empty?
|
||||
yield(debris.force_encoding(Encoding.default_external)) unless debris.empty?
|
||||
end
|
||||
|
||||
def read_backward(length)
|
||||
|
|
|
|||
Loading…
Reference in New Issue