Method: Zip::ZipEntry#read_c_dir_entry

Defined in:
lib/ruby_archive/handlers/rubyzip/zip/zip.rb

#read_c_dir_entry(io) ⇒ Object

:nodoc:all



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 589

def read_c_dir_entry(io)  #:nodoc:all
  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 = :symlink
    else
      raise ZipInternalError, "unknown file type #{'0%o' % (@externalFileAttributes >> 28)}"
    end
  else
    if name_is_directory?
      @ftype = :directory
    else
      @ftype = :file
    end
  end
  @local_header_size = calculate_local_header_size
end