module RecipeArchiveZip
Constants
- CENTRAL_SIG
- END_SIG
- LOCAL_SIG
- METHOD_DEFLATED
- METHOD_STORED
Public Instance Methods
Source
# File plugins/recipe.rb, line 67 def decompress(method, data, uncomp_size, flags) case method when METHOD_STORED data when METHOD_DEFLATED Zlib::Inflate.inflate(data) else raise "unsupported zip compression #{method}" if flags.nonzero? data end end
Source
# File plugins/recipe.rb, line 32 def each_entry(path) return enum_for(:each_entry, path) unless block_given? File.open(path, "rb") do |io| until io.eof? sig = read_u32(io) break unless sig == LOCAL_SIG _ver, flags, method, _time, _date, crc, comp_size, uncomp_size, name_len, extra_len = io.read(26).unpack("vvvvvVVVvv") name = io.read(name_len).force_encoding(Encoding::BINARY) io.read(extra_len) if extra_len.positive? data = io.read(comp_size) body = decompress(method, data, uncomp_size, flags) yield(name, body, crc) end end rescue StandardError nil end
Source
# File plugins/recipe.rb, line 61 def list_members(path) names = [] each_entry(path) { |name, _body, _crc| names << name } names end
Source
# File plugins/recipe.rb, line 53 def read_member(path, member_name) target = member_name.to_s each_entry(path) do |name, body, _crc| return truncate(body) if name == target end nil end
Source
# File plugins/recipe.rb, line 86 def read_u32(io) io.read(4)&.unpack1("V") end
Source
# File plugins/recipe.rb, line 80 def truncate(body) return body if body.bytesize <= Recipe::MAX_FILE_BYTES body.byteslice(0, Recipe::MAX_FILE_BYTES) end