Class: Omnizip::Buffer::MemoryArchive::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/buffer/memory_archive.rb

Overview

Entry wrapper with read capability

Wraps underlying ZIP entry to provide consistent interface for reading entry data from the stream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, stream) ⇒ Entry

Initialize entry wrapper

Parameters:



174
175
176
177
178
179
180
181
182
183
# File 'lib/omnizip/buffer/memory_archive.rb', line 174

def initialize(entry, stream)
  @entry = entry
  @stream = stream
  @name = entry.name
  @size = entry.size
  @compressed_size = entry.compressed_size
  @time = entry.time
  @comment = entry.comment
  @directory = entry.directory?
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



168
169
170
# File 'lib/omnizip/buffer/memory_archive.rb', line 168

def comment
  @comment
end

#compressed_sizeObject (readonly)

Returns the value of attribute compressed_size.



168
169
170
# File 'lib/omnizip/buffer/memory_archive.rb', line 168

def compressed_size
  @compressed_size
end

#nameObject (readonly)

Returns the value of attribute name.



168
169
170
# File 'lib/omnizip/buffer/memory_archive.rb', line 168

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



168
169
170
# File 'lib/omnizip/buffer/memory_archive.rb', line 168

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



168
169
170
# File 'lib/omnizip/buffer/memory_archive.rb', line 168

def time
  @time
end

Instance Method Details

#compression_methodSymbol

Get compression method

Returns:

  • (Symbol)

    Compression method (:store, :deflate, etc.)



218
219
220
# File 'lib/omnizip/buffer/memory_archive.rb', line 218

def compression_method
  @entry.compression_method
end

#crc32Integer

Get CRC32 checksum

Returns:

  • (Integer)

    CRC32 value



225
226
227
# File 'lib/omnizip/buffer/memory_archive.rb', line 225

def crc32
  @entry.crc32
end

#directory?Boolean

Check if entry is a directory

Returns:

  • (Boolean)

    True if directory entry



204
205
206
# File 'lib/omnizip/buffer/memory_archive.rb', line 204

def directory?
  @directory
end

#file?Boolean

Check if entry is a file

Returns:

  • (Boolean)

    True if file entry



211
212
213
# File 'lib/omnizip/buffer/memory_archive.rb', line 211

def file?
  !@directory
end

#read(size = nil) ⇒ String?

Read entry content

Examples:

Read entire entry

content = entry.read

Read in chunks

while (chunk = entry.read(8192))
  process_chunk(chunk)
end

Parameters:

  • size (Integer, nil) (defaults to: nil)

    Number of bytes to read (nil for all)

Returns:

  • (String, nil)

    Entry data or nil if EOF



197
198
199
# File 'lib/omnizip/buffer/memory_archive.rb', line 197

def read(size = nil)
  @stream.read(size)
end