Class: Zip::ZipEntry
Direct Known Subclasses
Constant Summary collapse
- STORED =
0- DEFLATED =
8- FSTYPE_FAT =
0- FSTYPE_AMIGA =
1- FSTYPE_VMS =
2- FSTYPE_UNIX =
3- FSTYPE_VM_CMS =
4- FSTYPE_ATARI =
5- FSTYPE_HPFS =
6- FSTYPE_MAC =
7- FSTYPE_Z_SYSTEM =
8- FSTYPE_CPM =
9- FSTYPE_TOPS20 =
10- FSTYPE_NTFS =
11- FSTYPE_QDOS =
12- FSTYPE_ACORN =
13- FSTYPE_VFAT =
14- FSTYPE_MVS =
15- FSTYPE_BEOS =
16- FSTYPE_TANDEM =
17- FSTYPE_THEOS =
18- FSTYPE_MAC_OSX =
19- FSTYPE_ATHEOS =
30- FSTYPES =
{ FSTYPE_FAT => 'FAT'.freeze, FSTYPE_AMIGA => 'Amiga'.freeze, FSTYPE_VMS => 'VMS (Vax or Alpha AXP)'.freeze, FSTYPE_UNIX => 'Unix'.freeze, FSTYPE_VM_CMS => 'VM/CMS'.freeze, FSTYPE_ATARI => 'Atari ST'.freeze, FSTYPE_HPFS => 'OS/2 or NT HPFS'.freeze, FSTYPE_MAC => 'Macintosh'.freeze, FSTYPE_Z_SYSTEM => 'Z-System'.freeze, FSTYPE_CPM => 'CP/M'.freeze, FSTYPE_TOPS20 => 'TOPS-20'.freeze, FSTYPE_NTFS => 'NTFS'.freeze, FSTYPE_QDOS => 'SMS/QDOS'.freeze, FSTYPE_ACORN => 'Acorn RISC OS'.freeze, FSTYPE_VFAT => 'Win32 VFAT'.freeze, FSTYPE_MVS => 'MVS'.freeze, FSTYPE_BEOS => 'BeOS'.freeze, FSTYPE_TANDEM => 'Tandem NSK'.freeze, FSTYPE_THEOS => 'Theos'.freeze, FSTYPE_MAC_OSX => 'Mac OS/X (Darwin)'.freeze, FSTYPE_ATHEOS => 'AtheOS'.freeze, }.freeze
- LOCAL_ENTRY_SIGNATURE =
0x04034b50- LOCAL_ENTRY_STATIC_HEADER_LENGTH =
30- LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH =
4+4+4
- CENTRAL_DIRECTORY_ENTRY_SIGNATURE =
0x02014b50- CDIR_ENTRY_STATIC_HEADER_LENGTH =
46
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#compressed_size ⇒ Object
Returns the value of attribute compressed_size.
-
#compression_method ⇒ Object
Returns the value of attribute compression_method.
-
#crc ⇒ Object
Returns the value of attribute crc.
-
#externalFileAttributes ⇒ Object
Returns the value of attribute externalFileAttributes.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#filepath ⇒ Object
readonly
:nodoc:.
-
#follow_symlinks ⇒ Object
Returns the value of attribute follow_symlinks.
-
#fstype ⇒ Object
Returns the value of attribute fstype.
-
#ftype ⇒ Object
readonly
:nodoc:.
-
#gp_flags ⇒ Object
Returns the value of attribute gp_flags.
-
#header_signature ⇒ Object
Returns the value of attribute header_signature.
-
#localHeaderOffset ⇒ Object
Returns the value of attribute localHeaderOffset.
-
#name ⇒ Object
Returns the value of attribute name.
-
#restore_ownership ⇒ Object
Returns the value of attribute restore_ownership.
-
#restore_permissions ⇒ Object
Returns the value of attribute restore_permissions.
-
#restore_times ⇒ Object
Returns the value of attribute restore_times.
-
#size ⇒ Object
Returns the value of attribute size.
-
#unix_gid ⇒ Object
Returns the value of attribute unix_gid.
-
#unix_perms ⇒ Object
Returns the value of attribute unix_perms.
-
#unix_uid ⇒ Object
Returns the value of attribute unix_uid.
-
#zipfile ⇒ Object
Returns the value of attribute zipfile.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#calculate_local_header_size ⇒ Object
:nodoc:all.
-
#cdir_header_size ⇒ Object
:nodoc:all.
-
#directory? ⇒ Boolean
(also: #is_directory)
Returns
trueif the entry is a directory. -
#extract(destPath = @name, &onExistsProc) ⇒ Object
Extracts entry to file destPath (defaults to @name).
-
#file? ⇒ Boolean
Returns
trueif the entry is a file. -
#file_stat(path) ⇒ Object
:nodoc:.
-
#gather_fileinfo_from_srcpath(srcPath) ⇒ Object
:nodoc:.
-
#get_extra_attributes_from_path(path) ⇒ Object
:nodoc:.
-
#get_input_stream(&aProc) ⇒ Object
Returns an IO like object for the given ZipEntry.
- #get_raw_input_stream(&aProc) ⇒ Object
- #gp_flags_for_write ⇒ Object
-
#initialize(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = Time.now) ⇒ ZipEntry
constructor
A new instance of ZipEntry.
-
#is_utf8? ⇒ Boolean
checking specifically for utf-8 as its the only encoding we can choose.
-
#local_entry_offset ⇒ Object
:nodoc:all.
-
#name_is_directory? ⇒ Boolean
:nodoc:all.
-
#next_header_offset ⇒ Object
:nodoc:all.
- #parent_as_string ⇒ Object
-
#read_c_dir_entry(io) ⇒ Object
:nodoc:all.
-
#read_local_entry(io) ⇒ Object
:nodoc:all.
-
#set_extra_attributes_on_path(destPath) ⇒ Object
:nodoc:.
-
#symlink? ⇒ Boolean
Returns
trueif the entry is a symlink. - #time ⇒ Object (also: #mtime)
- #time=(aTime) ⇒ Object
- #to_s ⇒ Object
-
#write_c_dir_entry(io) ⇒ Object
:nodoc:all.
-
#write_local_entry(io) ⇒ Object
:nodoc:all.
-
#write_to_zip_output_stream(aZipOutputStream) ⇒ Object
:nodoc:all.
Constructor Details
#initialize(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = Time.now) ⇒ ZipEntry
Returns a new instance of ZipEntry.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/zip/zip.rb', line 351 def initialize(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = Time.now) super() if name.starts_with("/") raise ZipEntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" end @localHeaderOffset = 0 @internalFileAttributes = 1 @externalFileAttributes = 0 @version = 52 # this library's version @ftype = nil # unspecified or unknown @filepath = nil if Zip::RUNNING_ON_WINDOWS @fstype = FSTYPE_FAT else @fstype = FSTYPE_UNIX end @zipfile, @comment, @compressed_size, @crc, @extra, @compression_method, @name, @size = zipfile, comment, compressed_size, crc, extra, compression_method, name, size @time = time @follow_symlinks = false @restore_times = true = false @restore_ownership = false # BUG: need an extra field to support uid/gid's @unix_uid = nil @unix_gid = nil @unix_perms = nil # @posix_acl = nil # @ntfs_acl = nil if name_is_directory? @ftype = :directory else @ftype = :file end unless ZipExtraField === @extra @extra = ZipExtraField.new(@extra.to_s) end @versionNeededToExtract = 0 #i doubt 0 is correct but it needs to be an integer end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def comment @comment end |
#compressed_size ⇒ Object
Returns the value of attribute compressed_size.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def compressed_size @compressed_size end |
#compression_method ⇒ Object
Returns the value of attribute compression_method.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def compression_method @compression_method end |
#crc ⇒ Object
Returns the value of attribute crc.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def crc @crc end |
#externalFileAttributes ⇒ Object
Returns the value of attribute externalFileAttributes.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def externalFileAttributes @externalFileAttributes end |
#extra ⇒ Object
Returns the value of attribute extra.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def extra @extra end |
#filepath ⇒ Object (readonly)
:nodoc:
349 350 351 |
# File 'lib/zip/zip.rb', line 349 def filepath @filepath end |
#follow_symlinks ⇒ Object
Returns the value of attribute follow_symlinks.
345 346 347 |
# File 'lib/zip/zip.rb', line 345 def follow_symlinks @follow_symlinks end |
#fstype ⇒ Object
Returns the value of attribute fstype.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def fstype @fstype end |
#ftype ⇒ Object (readonly)
:nodoc:
349 350 351 |
# File 'lib/zip/zip.rb', line 349 def ftype @ftype end |
#gp_flags ⇒ Object
Returns the value of attribute gp_flags.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def gp_flags @gp_flags end |
#header_signature ⇒ Object
Returns the value of attribute header_signature.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def header_signature @header_signature end |
#localHeaderOffset ⇒ Object
Returns the value of attribute localHeaderOffset.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def localHeaderOffset @localHeaderOffset end |
#name ⇒ Object
Returns the value of attribute name.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def name @name end |
#restore_ownership ⇒ Object
Returns the value of attribute restore_ownership.
346 347 348 |
# File 'lib/zip/zip.rb', line 346 def restore_ownership @restore_ownership end |
#restore_permissions ⇒ Object
Returns the value of attribute restore_permissions.
346 347 348 |
# File 'lib/zip/zip.rb', line 346 def end |
#restore_times ⇒ Object
Returns the value of attribute restore_times.
346 347 348 |
# File 'lib/zip/zip.rb', line 346 def restore_times @restore_times end |
#size ⇒ Object
Returns the value of attribute size.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def size @size end |
#unix_gid ⇒ Object
Returns the value of attribute unix_gid.
347 348 349 |
# File 'lib/zip/zip.rb', line 347 def unix_gid @unix_gid end |
#unix_perms ⇒ Object
Returns the value of attribute unix_perms.
347 348 349 |
# File 'lib/zip/zip.rb', line 347 def unix_perms @unix_perms end |
#unix_uid ⇒ Object
Returns the value of attribute unix_uid.
347 348 349 |
# File 'lib/zip/zip.rb', line 347 def unix_uid @unix_uid end |
#zipfile ⇒ Object
Returns the value of attribute zipfile.
342 343 344 |
# File 'lib/zip/zip.rb', line 342 def zipfile @zipfile end |
Class Method Details
.read_c_dir_entry(io) ⇒ Object
:nodoc:all
657 658 659 660 661 662 663 |
# File 'lib/zip/zip.rb', line 657 def ZipEntry.read_c_dir_entry(io) #:nodoc:all entry = new(io.path) entry.read_c_dir_entry(io) return entry rescue ZipError return nil end |
.read_local_entry(io) ⇒ Object
545 546 547 548 549 550 551 |
# File 'lib/zip/zip.rb', line 545 def ZipEntry.read_local_entry(io) entry = new(io.path) entry.read_local_entry(io) return entry rescue ZipError return nil end |
Instance Method Details
#<=>(other) ⇒ Object
759 760 761 |
# File 'lib/zip/zip.rb', line 759 def <=> (other) return to_s <=> other.to_s end |
#==(other) ⇒ Object
746 747 748 749 750 751 752 753 754 755 756 757 |
# File 'lib/zip/zip.rb', line 746 def == (other) return false unless other.class == self.class # Compares contents of local entry and exposed fields (@compression_method == other.compression_method && @crc == other.crc && @compressed_size == other.compressed_size && @size == other.size && @name == other.name && @extra == other.extra && @filepath == other.filepath && self.time.dos_equals(other.time)) end |
#calculate_local_header_size ⇒ Object
:nodoc:all
451 452 453 |
# File 'lib/zip/zip.rb', line 451 def calculate_local_header_size #:nodoc:all LOCAL_ENTRY_STATIC_HEADER_LENGTH + (@name ? @name.bytesize : 0) + (@extra ? @extra.local_size : 0) end |
#cdir_header_size ⇒ Object
:nodoc:all
455 456 457 458 |
# File 'lib/zip/zip.rb', line 455 def cdir_header_size #:nodoc:all CDIR_ENTRY_STATIC_HEADER_LENGTH + (@name ? @name.bytesize : 0) + (@extra ? @extra.c_dir_size : 0) + (@comment ? @comment.size : 0) end |
#directory? ⇒ Boolean Also known as: is_directory
Returns true if the entry is a directory.
425 426 427 428 |
# File 'lib/zip/zip.rb', line 425 def directory? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :directory end |
#extract(destPath = @name, &onExistsProc) ⇒ Object
Extracts entry to file destPath (defaults to @name).
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/zip/zip.rb', line 465 def extract(destPath = @name, &onExistsProc) onExistsProc ||= proc { false } if directory? create_directory(destPath, &onExistsProc) elsif file? write_file(destPath, &onExistsProc) elsif symlink? create_symlink(destPath, &onExistsProc) else raise RuntimeError, "unknown file type #{self.inspect}" end self end |
#file? ⇒ Boolean
Returns true if the entry is a file.
432 433 434 435 |
# File 'lib/zip/zip.rb', line 432 def file? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :file end |
#file_stat(path) ⇒ Object
:nodoc:
665 666 667 668 669 670 671 |
# File 'lib/zip/zip.rb', line 665 def file_stat(path) # :nodoc: if @follow_symlinks return File::stat(path) else return File::lstat(path) end end |
#gather_fileinfo_from_srcpath(srcPath) ⇒ Object
:nodoc:
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 |
# File 'lib/zip/zip.rb', line 797 def gather_fileinfo_from_srcpath(srcPath) # :nodoc: stat = file_stat(srcPath) case stat.ftype when 'file' if name_is_directory? raise ArgumentError, "entry name '#{newEntry}' indicates directory entry, but "+ "'#{srcPath}' is not a directory" end @ftype = :file when 'directory' if ! name_is_directory? @name += "/" end @ftype = :directory when 'link' if name_is_directory? raise ArgumentError, "entry name '#{newEntry}' indicates directory entry, but "+ "'#{srcPath}' is not a directory" end @ftype = :symlink else raise RuntimeError, "unknown file type: #{srcPath.inspect} #{stat.inspect}" end @filepath = srcPath get_extra_attributes_from_path(@filepath) end |
#get_extra_attributes_from_path(path) ⇒ Object
:nodoc:
673 674 675 676 677 678 679 680 |
# File 'lib/zip/zip.rb', line 673 def get_extra_attributes_from_path(path) # :nodoc: unless Zip::RUNNING_ON_WINDOWS stat = file_stat(path) @unix_uid = stat.uid @unix_gid = stat.gid @unix_perms = stat.mode & 07777 end end |
#get_input_stream(&aProc) ⇒ Object
Returns an IO like object for the given ZipEntry. Warning: may behave weird with symlinks.
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/zip/zip.rb', line 765 def get_input_stream(&aProc) if @ftype == :directory return yield(NullInputStream.instance) if block_given? return NullInputStream.instance elsif @filepath case @ftype when :file return File.open(@filepath, "rb", &aProc) when :symlink linkpath = File::readlink(@filepath) stringio = StringIO.new(linkpath) return yield(stringio) if block_given? return stringio else raise "unknown @ftype #{@ftype}" end else zis = ZipInputStream.new(@zipfile, localHeaderOffset) zis.get_next_entry if block_given? begin return yield(zis) ensure zis.close end else return zis end end end |
#get_raw_input_stream(&aProc) ⇒ Object
844 845 846 |
# File 'lib/zip/zip.rb', line 844 def get_raw_input_stream(&aProc) File.open(@zipfile, "rb", &aProc) end |
#gp_flags_for_write ⇒ Object
575 576 577 578 579 580 |
# File 'lib/zip/zip.rb', line 575 def gp_flags_for_write gp_flags = 0 gp_flags += 2048 if @name.encoding == Encoding::UTF_8 gp_flags end |
#is_utf8? ⇒ Boolean
checking specifically for utf-8 as its the only encoding we can choose
401 402 403 |
# File 'lib/zip/zip.rb', line 401 def is_utf8? #checking specifically for utf-8 as its the only encoding we can choose @gp_flags >> 11 == 1 end |
#local_entry_offset ⇒ Object
:nodoc:all
447 448 449 |
# File 'lib/zip/zip.rb', line 447 def local_entry_offset #:nodoc:all localHeaderOffset + @local_header_size end |
#name_is_directory? ⇒ Boolean
:nodoc:all
443 444 445 |
# File 'lib/zip/zip.rb', line 443 def name_is_directory? #:nodoc:all (%r{\/$} =~ @name) != nil end |
#next_header_offset ⇒ Object
:nodoc:all
460 461 462 |
# File 'lib/zip/zip.rb', line 460 def next_header_offset #:nodoc:all local_entry_offset + self.compressed_size end |
#parent_as_string ⇒ Object
838 839 840 841 842 |
# File 'lib/zip/zip.rb', line 838 def parent_as_string entry_name = name.chomp("/") slash_index = entry_name.rindex("/") slash_index ? entry_name.slice(0, slash_index+1) : nil end |
#read_c_dir_entry(io) ⇒ Object
:nodoc:all
582 583 584 585 586 587 588 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/zip/zip.rb', line 582 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 self.is_utf8? @name = @name.force_encoding('UTF-8') else @name = @name.force_encoding('CP437') end 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)}" end else if name_is_directory? @ftype = :directory else @ftype = :file end end @local_header_size = calculate_local_header_size end |
#read_local_entry(io) ⇒ Object
:nodoc:all
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/zip/zip.rb', line 500 def read_local_entry(io) #:nodoc:all @localHeaderOffset = io.tell staticSizedFieldsBuf = io.read(LOCAL_ENTRY_STATIC_HEADER_LENGTH) unless (staticSizedFieldsBuf.size==LOCAL_ENTRY_STATIC_HEADER_LENGTH) raise ZipError, "Premature end of file. Not enough data for zip entry local header" end @header_signature , @version , @fstype , @gp_flags , @compression_method, lastModTime , lastModDate , @crc , @compressed_size , @size , nameLength , extraLength = staticSizedFieldsBuf.unpack('VCCvvvvVVVvv') unless (@header_signature == LOCAL_ENTRY_SIGNATURE) raise ZipError, "Zip local header magic not found at location '#{localHeaderOffset}'" end set_time(lastModDate, lastModTime) @name = io.read(nameLength) if self.is_utf8? @name = @name.force_encoding('UTF-8') else @name = @name.force_encoding('CP437') end extra = io.read(extraLength) if (extra && extra.length != extraLength) raise ZipError, "Truncated local zip entry header" else if ZipExtraField === @extra @extra.merge(extra) else @extra = ZipExtraField.new(extra) end end @local_header_size = calculate_local_header_size end |
#set_extra_attributes_on_path(destPath) ⇒ Object
:nodoc:
682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/zip/zip.rb', line 682 def set_extra_attributes_on_path(destPath) # :nodoc: return unless (file? or directory?) case @fstype when FSTYPE_UNIX # BUG: does not update timestamps into account # ignore setuid/setgid bits by default. honor if @restore_ownership unix_perms_mask = 01777 unix_perms_mask = 07777 if (@restore_ownership) File::chmod(@unix_perms & unix_perms_mask, destPath) if ( && @unix_perms) File::chown(@unix_uid, @unix_gid, destPath) if (@restore_ownership && @unix_uid && @unix_gid && Process::egid == 0) # File::utimes() end end |
#symlink? ⇒ Boolean
Returns true if the entry is a symlink.
438 439 440 441 |
# File 'lib/zip/zip.rb', line 438 def symlink? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :link end |
#time ⇒ Object Also known as: mtime
405 406 407 408 409 410 411 412 413 |
# File 'lib/zip/zip.rb', line 405 def time if @extra["UniversalTime"] @extra["UniversalTime"].mtime else # Atandard time field in central directory has local time # under archive creator. Then, we can't get timezone. @time end end |
#time=(aTime) ⇒ Object
416 417 418 419 420 421 422 |
# File 'lib/zip/zip.rb', line 416 def time=(aTime) unless @extra.member?("UniversalTime") @extra.create("UniversalTime") end @extra["UniversalTime"].mtime = aTime @time = aTime end |
#to_s ⇒ Object
481 482 483 |
# File 'lib/zip/zip.rb', line 481 def to_s @name end |
#write_c_dir_entry(io) ⇒ Object
:nodoc:all
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/zip/zip.rb', line 697 def write_c_dir_entry(io) #:nodoc:all case @fstype when FSTYPE_UNIX ft = nil case @ftype when :file ft = 010 @unix_perms ||= 0644 when :directory ft = 004 @unix_perms ||= 0755 when :symlink ft = 012 @unix_perms ||= 0755 else raise ZipInternalError, "unknown file type #{self.inspect}" end @externalFileAttributes = (ft << 12 | (@unix_perms & 07777)) << 16 end io << [CENTRAL_DIRECTORY_ENTRY_SIGNATURE, @version , # version of encoding software @fstype , # filesystem type @versionNeededToExtract , # @versionNeededToExtract , self.gp_flags_for_write , # @gp_flags , @compression_method , @time.to_binary_dos_time , # @lastModTime , @time.to_binary_dos_date , # @lastModDate , @crc , @compressed_size , @size , @name ? @name.bytesize : 0 , @extra ? @extra.c_dir_length : 0 , @comment ? comment.length : 0 , 0 , # disk number start @internalFileAttributes , # file type (binary=0, text=1) @externalFileAttributes , # native filesystem attributes @localHeaderOffset , @name , @extra , @comment ].pack('VCCvvvvvVVVvvvvvVV') io << @name io << (@extra ? @extra.to_c_dir_bin : "") io << @comment end |
#write_local_entry(io) ⇒ Object
:nodoc:all
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/zip/zip.rb', line 553 def write_local_entry(io) #:nodoc:all @localHeaderOffset = io.tell io << [LOCAL_ENTRY_SIGNATURE , @versionNeededToExtract , self.gp_flags_for_write , # @gp_flags , @compression_method , @time.to_binary_dos_time , # @lastModTime , @time.to_binary_dos_date , # @lastModDate , @crc , @compressed_size , @size , @name ? @name.bytesize : 0, @extra? @extra.local_length : 0 ].pack('VvvvvvVVVvv') io << @name io << (@extra ? @extra.to_local_bin : "") end |
#write_to_zip_output_stream(aZipOutputStream) ⇒ Object
:nodoc:all
827 828 829 830 831 832 833 834 835 836 |
# File 'lib/zip/zip.rb', line 827 def write_to_zip_output_stream(aZipOutputStream) #:nodoc:all if @ftype == :directory aZipOutputStream.put_next_entry(self) elsif @filepath aZipOutputStream.put_next_entry(self) get_input_stream { |is| IOExtras.copy_stream(aZipOutputStream, is) } else aZipOutputStream.copy_raw_entry(self) end end |