-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io_buffer.rb - use StringIO instead of String
- Loading branch information
Showing
1 changed file
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
# 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 empty? | ||
length.zero? | ||
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 |