class Gem::Package::TarWriter::BoundedStream
允许写入有限数量数据的 IO 包装器
属性
可写入的最大字节数
已写入的字节数
Public Class Methods
Source
# File lib/rubygems/package/tar_writer.rb, line 33 def initialize(io, limit) @io = io @limit = limit @written = 0 end
包装 io,允许写入最多 limit 字节
Public Instance Methods
Source
# File lib/rubygems/package/tar_writer.rb, line 43 def write(data) if data.bytesize + @written > @limit raise FileOverflow, "You tried to feed more data than fits in the file." end @io.write data @written += data.bytesize data.bytesize end
将 data 写入 IO,如果写入的字节数将超过 limit,则会引发 FileOverflow 异常