class Gem::Package::TarWriter::BoundedStream

IO 包装器,允许写入有限数量的数据

属性

limit[R]

可以写入的最大字节数

written[R]

已写入的字节数

公共类方法

new(io, limit) 点击切换源码

包装 io 并允许写入最多 limit 字节

# File rubygems/package/tar_writer.rb, line 33
def initialize(io, limit)
  @io = io
  @limit = limit
  @written = 0
end

公共实例方法

write(data) 点击切换源码

data 写入 IO,如果字节数将超过 limit,则抛出 FileOverflow 异常

# File 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