Sha256: 2566b6cf7363a46c92e50b1a252fc773115d95c87bb025a8313b3ecc36fcc18e
Contents?: true
Size: 673 Bytes
Versions: 19
Compression:
Stored size: 673 Bytes
Contents
# frozen_string_literal: true # A tiny wrapper over any object that supports :<<. # Adds :tell and :advance_position_by. class ZipTricks::WriteAndTell def initialize(io) @io = io @pos = 0 end def <<(bytes) return self if bytes.nil? binary_bytes = binary(bytes) @io << binary_bytes @pos += binary_bytes.bytesize self end def advance_position_by(num_bytes) @pos += num_bytes end def tell @pos end private def binary(str) return str if str.encoding == Encoding::BINARY str.force_encoding(Encoding::BINARY) rescue RuntimeError # the string is frozen str.dup.force_encoding(Encoding::BINARY) end end
Version data entries
19 entries across 19 versions & 1 rubygems