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 9, 2021
1 parent a941531 commit 833772e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/puma/io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
# 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

alias_method :to_s, :string

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

0 comments on commit 833772e

Please sign in to comment.