Class: Omnizip::Zip::Entry
- Inherits:
-
Object
- Object
- Omnizip::Zip::Entry
- Defined in:
- lib/omnizip/zip/entry.rb
Overview
Rubyzip-compatible Entry class Wraps CentralDirectoryHeader with rubyzip API
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#ftype ⇒ Object
readonly
Returns the value of attribute ftype.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality comparison.
-
#comment ⇒ Object
Get comment.
-
#comment=(value) ⇒ Object
Set comment.
-
#compressed_size ⇒ Object
Compressed size.
-
#compression_method ⇒ Object
Compression method ID.
-
#crc ⇒ Object
CRC32 checksum.
-
#directory? ⇒ Boolean
(also: #is_directory)
Is this a directory?.
-
#extra ⇒ Object
Get extra field.
-
#extra=(value) ⇒ Object
Set extra field.
-
#extract(dest_path) ⇒ Object
Extract this entry to a destination path Note: This requires access to the archive file.
-
#file? ⇒ Boolean
Is this a file?.
-
#get_input_stream ⇒ Object
Get input stream for this entry Note: This requires access to the archive file.
-
#initialize(header, filepath: nil) ⇒ Entry
constructor
Create entry from CentralDirectoryHeader.
-
#metadata ⇒ Omnizip::Metadata::EntryMetadata
Get metadata for this entry.
-
#name ⇒ Object
Entry name (path within archive).
-
#save_metadata ⇒ Object
Save metadata changes Marks the entry as modified so changes are written on archive close.
-
#size ⇒ Object
Uncompressed size.
-
#symlink? ⇒ Boolean
Is this a symbolic link?.
-
#time ⇒ Object
Modification time.
-
#to_s ⇒ Object
String representation.
-
#unix_perms ⇒ Object
Unix permissions.
-
#unix_perms=(perms) ⇒ Object
Set Unix permissions.
Constructor Details
#initialize(header, filepath: nil) ⇒ Entry
Create entry from CentralDirectoryHeader
11 12 13 14 15 |
# File 'lib/omnizip/zip/entry.rb', line 11 def initialize(header, filepath: nil) @header = header @filepath = filepath @ftype = header.directory? ? :directory : :file end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
8 9 10 |
# File 'lib/omnizip/zip/entry.rb', line 8 def filepath @filepath end |
#ftype ⇒ Object (readonly)
Returns the value of attribute ftype.
8 9 10 |
# File 'lib/omnizip/zip/entry.rb', line 8 def ftype @ftype end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
8 9 10 |
# File 'lib/omnizip/zip/entry.rb', line 8 def header @header end |
Instance Method Details
#==(other) ⇒ Object
Equality comparison
127 128 129 130 131 |
# File 'lib/omnizip/zip/entry.rb', line 127 def ==(other) return false unless other.is_a?(Entry) name == other.name end |
#comment ⇒ Object
Get comment
64 65 66 |
# File 'lib/omnizip/zip/entry.rb', line 64 def comment header.comment || "" end |
#comment=(value) ⇒ Object
Set comment
69 70 71 |
# File 'lib/omnizip/zip/entry.rb', line 69 def comment=(value) header.comment = value end |
#compressed_size ⇒ Object
Compressed size
28 29 30 |
# File 'lib/omnizip/zip/entry.rb', line 28 def compressed_size header.compressed_size end |
#compression_method ⇒ Object
Compression method ID
38 39 40 |
# File 'lib/omnizip/zip/entry.rb', line 38 def compression_method header.compression_method end |
#crc ⇒ Object
CRC32 checksum
33 34 35 |
# File 'lib/omnizip/zip/entry.rb', line 33 def crc header.crc32 end |
#directory? ⇒ Boolean Also known as: is_directory
Is this a directory?
48 49 50 |
# File 'lib/omnizip/zip/entry.rb', line 48 def directory? @ftype == :directory end |
#extra ⇒ Object
Get extra field
74 75 76 |
# File 'lib/omnizip/zip/entry.rb', line 74 def extra header.extra_field || "" end |
#extra=(value) ⇒ Object
Set extra field
79 80 81 |
# File 'lib/omnizip/zip/entry.rb', line 79 def extra=(value) header.extra_field = value end |
#extract(dest_path) ⇒ Object
Extract this entry to a destination path Note: This requires access to the archive file
109 110 111 112 |
# File 'lib/omnizip/zip/entry.rb', line 109 def extract(dest_path) raise NotImplementedError, "Entry#extract requires File context. Use Omnizip::Zip::File#extract instead" end |
#file? ⇒ Boolean
Is this a file?
54 55 56 |
# File 'lib/omnizip/zip/entry.rb', line 54 def file? @ftype == :file end |
#get_input_stream ⇒ Object
Get input stream for this entry Note: This requires access to the archive file
116 117 118 119 |
# File 'lib/omnizip/zip/entry.rb', line 116 def get_input_stream raise NotImplementedError, "Entry#get_input_stream requires File context" end |
#metadata ⇒ Omnizip::Metadata::EntryMetadata
Get metadata for this entry
95 96 97 |
# File 'lib/omnizip/zip/entry.rb', line 95 def @metadata ||= Omnizip::Metadata::EntryMetadata.new(self) end |
#name ⇒ Object
Entry name (path within archive)
18 19 20 |
# File 'lib/omnizip/zip/entry.rb', line 18 def name header.filename end |
#save_metadata ⇒ Object
Save metadata changes Marks the entry as modified so changes are written on archive close
101 102 103 104 105 |
# File 'lib/omnizip/zip/entry.rb', line 101 def # Changes are already applied to the header # This is a convenience method for the API .reset_modified end |
#size ⇒ Object
Uncompressed size
23 24 25 |
# File 'lib/omnizip/zip/entry.rb', line 23 def size header.uncompressed_size end |
#symlink? ⇒ Boolean
Is this a symbolic link?
59 60 61 |
# File 'lib/omnizip/zip/entry.rb', line 59 def symlink? false # Not supported yet end |
#time ⇒ Object
Modification time
43 44 45 |
# File 'lib/omnizip/zip/entry.rb', line 43 def time dos_time_to_time(header.last_mod_date, header.last_mod_time) end |
#to_s ⇒ Object
String representation
122 123 124 |
# File 'lib/omnizip/zip/entry.rb', line 122 def to_s name end |
#unix_perms ⇒ Object
Unix permissions
84 85 86 |
# File 'lib/omnizip/zip/entry.rb', line 84 def unix_perms header. end |
#unix_perms=(perms) ⇒ Object
Set Unix permissions
89 90 91 |
# File 'lib/omnizip/zip/entry.rb', line 89 def unix_perms=(perms) header. = perms end |