Class: Zippo::ZipMember
- Inherits:
-
Object
- Object
- Zippo::ZipMember
- Extended by:
- Forwardable
- Defined in:
- lib/zippo/zip_member.rb
Overview
A member of a Zip archive file.
Instance Method Summary collapse
-
#directory? ⇒ Boolean
True if the member is a directory, False otherwise.
-
#initialize(io, header) ⇒ ZipMember
constructor
A new instance of ZipMember.
-
#name ⇒ String
The name of the member.
-
#read ⇒ String
Reads (and possibly uncompresses) the member’s data.
-
#with_name(name) ⇒ ZipMember
Duplicates this zip member and overrides the name.
-
#write_to(out, preferred_method = Filter::DeflateCompressor::METHOD, recompress = false) ⇒ Integer
Writes the member data to the specified IO using the specified compression method.
Constructor Details
#initialize(io, header) ⇒ ZipMember
Returns a new instance of ZipMember.
10 11 12 13 |
# File 'lib/zippo/zip_member.rb', line 10 def initialize(io, header) @io = io @header = header end |
Instance Method Details
#directory? ⇒ Boolean
Returns True if the member is a directory, False otherwise.
22 23 24 |
# File 'lib/zippo/zip_member.rb', line 22 def directory? name.end_with? '/' end |
#name ⇒ String
Returns the name of the member.
16 17 18 |
# File 'lib/zippo/zip_member.rb', line 16 def name @name ||= @header.name end |
#read ⇒ String
Reads (and possibly uncompresses) the member’s data
32 33 34 35 |
# File 'lib/zippo/zip_member.rb', line 32 def read seek_to_compressed_data uncompressor.uncompress end |
#with_name(name) ⇒ ZipMember
Duplicates this zip member and overrides the name.
41 42 43 44 45 |
# File 'lib/zippo/zip_member.rb', line 41 def with_name(name) dup.tap do |obj| obj.instance_variable_set :@name, name end end |
#write_to(out, preferred_method = Filter::DeflateCompressor::METHOD, recompress = false) ⇒ Integer
Writes the member data to the specified IO using the specified compression method.
56 57 58 59 60 61 62 63 64 |
# File 'lib/zippo/zip_member.rb', line 56 def write_to(out, preferred_method = Filter::DeflateCompressor::METHOD, recompress = false) seek_to_compressed_data if recompress Filter::Compressor.for(preferred_method).new(uncompressor).compress_to(out) else IO.copy_stream @io, out, @header.compressed_size return @header.compressed_size, @header.uncompressed_size, @header.crc32 end end |