2021-05-24 01:24:22 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-27 04:26:14 +08:00
|
|
|
module Zip
|
|
|
|
module IOExtras
|
|
|
|
# Implements many of the output convenience methods of IO.
|
|
|
|
# relies on <<
|
|
|
|
module AbstractOutputStream
|
|
|
|
include FakeIO
|
|
|
|
|
|
|
|
def write(data)
|
|
|
|
self << data
|
|
|
|
data.to_s.bytesize
|
|
|
|
end
|
|
|
|
|
|
|
|
def print(*params)
|
2019-09-27 04:46:00 +08:00
|
|
|
self << params.join($OUTPUT_FIELD_SEPARATOR) << $OUTPUT_RECORD_SEPARATOR.to_s
|
2013-08-27 04:26:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def printf(a_format_string, *params)
|
2017-06-29 10:57:12 +08:00
|
|
|
self << format(a_format_string, *params)
|
2013-08-27 04:26:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def putc(an_object)
|
|
|
|
self << case an_object
|
2017-01-08 14:38:14 +08:00
|
|
|
when Integer
|
2013-08-27 04:26:14 +08:00
|
|
|
an_object.chr
|
|
|
|
when String
|
|
|
|
an_object
|
|
|
|
else
|
2017-01-08 14:38:14 +08:00
|
|
|
raise TypeError, 'putc: Only Integer and String supported'
|
2013-08-27 04:26:14 +08:00
|
|
|
end
|
|
|
|
an_object
|
|
|
|
end
|
|
|
|
|
|
|
|
def puts(*params)
|
|
|
|
params << "\n" if params.empty?
|
|
|
|
params.flatten.each do |element|
|
|
|
|
val = element.to_s
|
|
|
|
self << val
|
|
|
|
self << "\n" unless val[-1, 1] == "\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|