Class: Omnizip::Zip::Entry
- Inherits:
-
Object
- Object
- Omnizip::Zip::Entry
- Includes:
- 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?.
- #entry_directory? ⇒ Boolean
- #entry_mtime ⇒ Object
- #entry_name ⇒ Object
- #entry_size ⇒ Object
-
#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
18 19 20 21 22 |
# File 'lib/omnizip/zip/entry.rb', line 18 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.
10 11 12 |
# File 'lib/omnizip/zip/entry.rb', line 10 def filepath @filepath end |
#ftype ⇒ Object (readonly)
Returns the value of attribute ftype.
10 11 12 |
# File 'lib/omnizip/zip/entry.rb', line 10 def ftype @ftype end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
10 11 12 |
# File 'lib/omnizip/zip/entry.rb', line 10 def header @header end |
Instance Method Details
#==(other) ⇒ Object
Equality comparison
134 135 136 137 138 |
# File 'lib/omnizip/zip/entry.rb', line 134 def ==(other) return false unless other.is_a?(Entry) name == other.name end |
#comment ⇒ Object
Get comment
71 72 73 |
# File 'lib/omnizip/zip/entry.rb', line 71 def comment header.comment || "" end |
#comment=(value) ⇒ Object
Set comment
76 77 78 |
# File 'lib/omnizip/zip/entry.rb', line 76 def comment=(value) header.comment = value end |
#compressed_size ⇒ Object
Compressed size
35 36 37 |
# File 'lib/omnizip/zip/entry.rb', line 35 def compressed_size header.compressed_size end |
#compression_method ⇒ Object
Compression method ID
45 46 47 |
# File 'lib/omnizip/zip/entry.rb', line 45 def compression_method header.compression_method end |
#crc ⇒ Object
CRC32 checksum
40 41 42 |
# File 'lib/omnizip/zip/entry.rb', line 40 def crc header.crc32 end |
#directory? ⇒ Boolean Also known as: is_directory
Is this a directory?
55 56 57 |
# File 'lib/omnizip/zip/entry.rb', line 55 def directory? @ftype == :directory end |
#entry_directory? ⇒ Boolean
13 |
# File 'lib/omnizip/zip/entry.rb', line 13 def entry_directory? = directory? |
#entry_mtime ⇒ Object
15 |
# File 'lib/omnizip/zip/entry.rb', line 15 def entry_mtime = time |
#entry_name ⇒ Object
12 |
# File 'lib/omnizip/zip/entry.rb', line 12 def entry_name = name |
#entry_size ⇒ Object
14 |
# File 'lib/omnizip/zip/entry.rb', line 14 def entry_size = size |
#extra ⇒ Object
Get extra field
81 82 83 |
# File 'lib/omnizip/zip/entry.rb', line 81 def extra header.extra_field || "" end |
#extra=(value) ⇒ Object
Set extra field
86 87 88 |
# File 'lib/omnizip/zip/entry.rb', line 86 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
116 117 118 119 |
# File 'lib/omnizip/zip/entry.rb', line 116 def extract(dest_path) raise NotImplementedError, "Entry#extract requires File context. Use Omnizip::Zip::File#extract instead" end |
#file? ⇒ Boolean
Is this a file?
61 62 63 |
# File 'lib/omnizip/zip/entry.rb', line 61 def file? @ftype == :file end |
#get_input_stream ⇒ Object
Get input stream for this entry Note: This requires access to the archive file
123 124 125 126 |
# File 'lib/omnizip/zip/entry.rb', line 123 def get_input_stream raise NotImplementedError, "Entry#get_input_stream requires File context" end |
#metadata ⇒ Omnizip::Metadata::EntryMetadata
Get metadata for this entry
102 103 104 |
# File 'lib/omnizip/zip/entry.rb', line 102 def @metadata ||= Omnizip::Metadata::EntryMetadata.new(self) end |
#name ⇒ Object
Entry name (path within archive)
25 26 27 |
# File 'lib/omnizip/zip/entry.rb', line 25 def name header.filename end |
#save_metadata ⇒ Object
Save metadata changes Marks the entry as modified so changes are written on archive close
108 109 110 111 112 |
# File 'lib/omnizip/zip/entry.rb', line 108 def # Changes are already applied to the header # This is a convenience method for the API .reset_modified end |
#size ⇒ Object
Uncompressed size
30 31 32 |
# File 'lib/omnizip/zip/entry.rb', line 30 def size header.uncompressed_size end |
#symlink? ⇒ Boolean
Is this a symbolic link?
66 67 68 |
# File 'lib/omnizip/zip/entry.rb', line 66 def symlink? false # Not supported yet end |
#time ⇒ Object
Modification time
50 51 52 |
# File 'lib/omnizip/zip/entry.rb', line 50 def time dos_time_to_time(header.last_mod_date, header.last_mod_time) end |
#to_s ⇒ Object
String representation
129 130 131 |
# File 'lib/omnizip/zip/entry.rb', line 129 def to_s name end |
#unix_perms ⇒ Object
Unix permissions
91 92 93 |
# File 'lib/omnizip/zip/entry.rb', line 91 def unix_perms header. end |
#unix_perms=(perms) ⇒ Object
Set Unix permissions
96 97 98 |
# File 'lib/omnizip/zip/entry.rb', line 96 def unix_perms=(perms) header. = perms end |