Class: Omnizip::Zip::Entry

Inherits:
Object
  • Object
show all
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



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

#filepathObject (readonly)

Returns the value of attribute filepath.



8
9
10
# File 'lib/omnizip/zip/entry.rb', line 8

def filepath
  @filepath
end

#ftypeObject (readonly)

Returns the value of attribute ftype.



8
9
10
# File 'lib/omnizip/zip/entry.rb', line 8

def ftype
  @ftype
end

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

#commentObject

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_sizeObject

Compressed size



28
29
30
# File 'lib/omnizip/zip/entry.rb', line 28

def compressed_size
  header.compressed_size
end

#compression_methodObject

Compression method ID



38
39
40
# File 'lib/omnizip/zip/entry.rb', line 38

def compression_method
  header.compression_method
end

#crcObject

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?

Returns:

  • (Boolean)


48
49
50
# File 'lib/omnizip/zip/entry.rb', line 48

def directory?
  @ftype == :directory
end

#extraObject

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

Raises:

  • (NotImplementedError)


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?

Returns:

  • (Boolean)


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

def file?
  @ftype == :file
end

#get_input_streamObject

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

Raises:

  • (NotImplementedError)


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

#metadataOmnizip::Metadata::EntryMetadata

Get metadata for this entry

Returns:



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

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

#nameObject

Entry name (path within archive)



18
19
20
# File 'lib/omnizip/zip/entry.rb', line 18

def name
  header.filename
end

#save_metadataObject

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

#sizeObject

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?

Returns:

  • (Boolean)


59
60
61
# File 'lib/omnizip/zip/entry.rb', line 59

def symlink?
  false # Not supported yet
end

#timeObject

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_sObject

String representation



122
123
124
# File 'lib/omnizip/zip/entry.rb', line 122

def to_s
  name
end

#unix_permsObject

Unix permissions



84
85
86
# File 'lib/omnizip/zip/entry.rb', line 84

def unix_perms
  header.unix_permissions
end

#unix_perms=(perms) ⇒ Object

Set Unix permissions



89
90
91
# File 'lib/omnizip/zip/entry.rb', line 89

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