@@ -1034,9 +1034,10 @@ class FIFO
10341034 def initialize ( from_encoding , encoding , log , max_line_size = nil )
10351035 @from_encoding = from_encoding
10361036 @encoding = encoding
1037- @need_enc = from_encoding != encoding
1038- @buffer = '' . force_encoding ( from_encoding )
1039- @eol = "\n " . encode ( from_encoding ) . freeze
1037+ @append_encoding = from_encoding || encoding
1038+ @need_enc = encoding && from_encoding && ( from_encoding != encoding )
1039+ @buffer = '' . force_encoding ( @append_encoding || Encoding ::ASCII_8BIT )
1040+ @eol = "\n " . encode ( @append_encoding || Encoding ::ASCII_8BIT ) . freeze
10401041 @max_line_size = max_line_size
10411042 @skip_current_line = false
10421043 @skipping_current_line_bytesize = 0
@@ -1056,11 +1057,13 @@ def <<(chunk)
10561057 # Feeding a string that has its encoding attribute set to any double-byte or
10571058 # quad-byte encoding to IO#readpartial as the second arguments results in an
10581059 # assertion failure on Ruby < 2.4.0 for unknown reasons.
1059- orig_encoding = chunk . encoding
1060- chunk . force_encoding ( from_encoding )
1060+ if @append_encoding
1061+ orig_encoding = chunk . encoding
1062+ chunk . force_encoding ( @append_encoding )
1063+ end
10611064 @buffer << chunk
10621065 # Thus the encoding needs to be reverted back here
1063- chunk . force_encoding ( orig_encoding )
1066+ chunk . force_encoding ( orig_encoding ) if @append_encoding
10641067 end
10651068
10661069 def convert ( s )
@@ -1143,7 +1146,7 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:,
11431146 @read_bytes_limit_per_second = read_bytes_limit_per_second
11441147 @receive_lines = receive_lines
11451148 @open_on_every_update = open_on_every_update
1146- @fifo = FIFO . new ( from_encoding || Encoding :: ASCII_8BIT , encoding || Encoding :: ASCII_8BIT , log , max_line_size )
1149+ @fifo = FIFO . new ( from_encoding , encoding , log , max_line_size )
11471150 @lines = [ ]
11481151 @io = nil
11491152 @notify_mutex = Mutex . new
0 commit comments