Skip to content

Commit

Permalink
io_buffer.rb - use StringIO instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Apr 12, 2021
1 parent ee63f22 commit 36d6253
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/puma/io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# frozen_string_literal: true

require 'stringio'

module Puma
class IOBuffer < String
def append(*args)
args.each { |a| concat(a) }
class IOBuffer < StringIO
def initialize
super.binmode
end

def reset
truncate 0
rewind
end

alias reset clear
def read
rewind
super.tap { |s| truncate 0; rewind }
end

# don't use, added just for existing CI tests
alias_method :to_s, :string

# before Ruby 2.5, `write` would only take one argument
if RUBY_VERSION >= '2.5' && RUBY_ENGINE != 'truffleruby'
alias_method :append, :write
else
def append(*strs)
strs.each { |str| write str }
end
end
end
end

0 comments on commit 36d6253

Please sign in to comment.