Class: Zip::ZipEntry

Inherits:
Object show all
Defined in:
lib/javaclass/gems/zip_file.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#read_c_dir_entry(io) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/javaclass/gems/zip_file.rb', line 16

def read_c_dir_entry(io)  
  staticSizedFieldsBuf = io.read(CDIR_ENTRY_STATIC_HEADER_LENGTH)
  unless (staticSizedFieldsBuf.size == CDIR_ENTRY_STATIC_HEADER_LENGTH)
    raise ZipError, "Premature end of file. Not enough data for zip cdir entry header"
  end

  @header_signature      ,
  @version               , # version of encoding software
  @fstype                , # filesystem type
  @versionNeededToExtract,
  @gp_flags              ,
  @compression_method    ,
  lastModTime            ,
  lastModDate            ,
  @crc                   ,
  @compressed_size       ,
  @size                  ,
  nameLength             ,
  extraLength            ,
  commentLength          ,
  diskNumberStart        ,
  @internalFileAttributes,
  @externalFileAttributes,
  @localHeaderOffset     ,
  @name                  ,
  @extra                 ,
  @comment               = staticSizedFieldsBuf.unpack('VCCvvvvvVVVvvvvvVV')

  unless @header_signature == CENTRAL_DIRECTORY_ENTRY_SIGNATURE
    raise ZipError, "Zip local header magic not found at location '#{localHeaderOffset}'"
  end
  set_time(lastModDate, lastModTime)

  @name = io.read(nameLength)
  if ZipExtraField === @extra
    @extra.merge(io.read(extraLength))
  else
    @extra = ZipExtraField.new(io.read(extraLength))
  end
  @comment = io.read(commentLength)
  unless (@comment && @comment.length == commentLength)
    raise ZipError, "Truncated cdir zip entry header"
  end

  case @fstype
    when FSTYPE_UNIX
      @unix_perms = (@externalFileAttributes >> 16) & 07777
  
      case (@externalFileAttributes >> 28)
      when 04
        @ftype = :directory
      when 010
        @ftype = :file
      when 012
        @ftype = :link
      else
        # raise ZipInternalError, "unknown file type #{'0%o' % (@externalFileAttributes >> 28)}"
        
        # PKZIP format see http://www.pkware.com/documents/APPNOTE/APPNOTE-6.3.0.TXT
        # external file attributes: (4 bytes)
        # The mapping of the external attributes is host-system dependent (see 'version made by').
        # For MS-DOS, the low order byte is the MS-DOS directory attribute byte. If input came 
        # from standard input, this field is set to zero.
        # for the meaning of these flags see http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute

        # unknown flag, fall back to name detection
        if name_is_directory?
          @ftype = :directory
        else
          @ftype = :file
        end
        
      end
      
    else
      if name_is_directory?
        @ftype = :directory
      else
        @ftype = :file
      end
    end
end

#strict_read_c_dir_entryObject

uncomment next method to avoid swallowing errors, else we get nil entries later. def ZipEntry.read_c_dir_entry(io)

entry = new(io.path)
entry.read_c_dir_entry(io)
return entry

end



14
# File 'lib/javaclass/gems/zip_file.rb', line 14

alias :strict_read_c_dir_entry read_c_dir_entry