Class: Omnizip::Zip::Entry

Inherits:
Object
  • Object
show all
Includes:
Entry
Defined in:
lib/omnizip/zip/entry.rb

Overview

Rubyzip-compatible Entry class Wraps CentralDirectoryHeader with rubyzip API

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filepathObject (readonly)

Returns the value of attribute filepath.



10
11
12
# File 'lib/omnizip/zip/entry.rb', line 10

def filepath
  @filepath
end

#ftypeObject (readonly)

Returns the value of attribute ftype.



10
11
12
# File 'lib/omnizip/zip/entry.rb', line 10

def ftype
  @ftype
end

#headerObject (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

#commentObject

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_sizeObject

Compressed size



35
36
37
# File 'lib/omnizip/zip/entry.rb', line 35

def compressed_size
  header.compressed_size
end

#compression_methodObject

Compression method ID



45
46
47
# File 'lib/omnizip/zip/entry.rb', line 45

def compression_method
  header.compression_method
end

#crcObject

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?

Returns:

  • (Boolean)


55
56
57
# File 'lib/omnizip/zip/entry.rb', line 55

def directory?
  @ftype == :directory
end

#entry_directory?Boolean

Returns:

  • (Boolean)


13
# File 'lib/omnizip/zip/entry.rb', line 13

def entry_directory? = directory?

#entry_mtimeObject



15
# File 'lib/omnizip/zip/entry.rb', line 15

def entry_mtime = time

#entry_nameObject



12
# File 'lib/omnizip/zip/entry.rb', line 12

def entry_name = name

#entry_sizeObject



14
# File 'lib/omnizip/zip/entry.rb', line 14

def entry_size = size

#extraObject

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

Raises:

  • (NotImplementedError)


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?

Returns:

  • (Boolean)


61
62
63
# File 'lib/omnizip/zip/entry.rb', line 61

def file?
  @ftype == :file
end

#get_input_streamObject

Get input stream for this entry Note: This requires access to the archive file

Raises:

  • (NotImplementedError)


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

#metadataOmnizip::Metadata::EntryMetadata

Get metadata for this entry

Returns:



102
103
104
# File 'lib/omnizip/zip/entry.rb', line 102

def 
  @metadata ||= Omnizip::Metadata::EntryMetadata.new(self)
end

#nameObject

Entry name (path within archive)



25
26
27
# File 'lib/omnizip/zip/entry.rb', line 25

def name
  header.filename
end

#save_metadataObject

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

#sizeObject

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?

Returns:

  • (Boolean)


66
67
68
# File 'lib/omnizip/zip/entry.rb', line 66

def symlink?
  false # Not supported yet
end

#timeObject

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_sObject

String representation



129
130
131
# File 'lib/omnizip/zip/entry.rb', line 129

def to_s
  name
end

#unix_permsObject

Unix permissions



91
92
93
# File 'lib/omnizip/zip/entry.rb', line 91

def unix_perms
  header.unix_permissions
end

#unix_perms=(perms) ⇒ Object

Set Unix permissions



96
97
98
# File 'lib/omnizip/zip/entry.rb', line 96

def unix_perms=(perms)
  header.unix_permissions = perms
end