Class: Zip::ZipEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/zip_entry.rb

Direct Known Subclasses

ZipStreamableDirectory, ZipStreamableStream

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
VERSION_NEEDED_TO_EXTRACT =
20
CENTRAL_DIRECTORY_ENTRY_SIGNATURE =
0x02014b50
CDIR_ENTRY_STATIC_HEADER_LENGTH =
46

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = DOSTime.now) ⇒ ZipEntry

Returns a new instance of ZipEntry.



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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/zip/zip_entry.rb', line 61

def initialize(zipfile = "", name = "", comment = "", extra = "",
               compressed_size = 0, crc = 0, 
               compression_method = ZipEntry::DEFLATED, size = 0,
               time  = DOSTime.now)
  super()
  if name.start_with?("/")
    raise ZipEntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
  end
  @localHeaderOffset = 0
  @local_header_size = 0
  @internalFileAttributes = 1
  @externalFileAttributes = 0
  @header_signature = CENTRAL_DIRECTORY_ENTRY_SIGNATURE
  @versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT
  @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 = zipfile
  @comment = comment
  @compressed_size = compressed_size
  @crc = crc
  @extra = extra
  @compression_method = compression_method
  @name = name
  @size = size
  @time = time
  @gp_flags = 0

  @follow_symlinks = false

  @restore_times = true
  @restore_permissions = 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

  @dirty = false
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def comment
  @comment
end

#compressed_sizeObject

Returns the value of attribute compressed_size.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def compressed_size
  @compressed_size
end

#compression_methodObject

Returns the value of attribute compression_method.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def compression_method
  @compression_method
end

#crcObject

Returns the value of attribute crc.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def crc
  @crc
end

#dirtyObject

Returns the value of attribute dirty.



58
59
60
# File 'lib/zip/zip_entry.rb', line 58

def dirty
  @dirty
end

#externalFileAttributesObject

Returns the value of attribute externalFileAttributes.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def externalFileAttributes
  @externalFileAttributes
end

#extraObject

Returns the value of attribute extra.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def extra
  @extra
end

#filepathObject (readonly)

:nodoc:



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

def filepath
  @filepath
end

Returns the value of attribute follow_symlinks.



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

def follow_symlinks
  @follow_symlinks
end

#fstypeObject

Returns the value of attribute fstype.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def fstype
  @fstype
end

#ftypeObject (readonly)

:nodoc:



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

def ftype
  @ftype
end

#gp_flagsObject

Returns the value of attribute gp_flags.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def gp_flags
  @gp_flags
end

#header_signatureObject

Returns the value of attribute header_signature.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def header_signature
  @header_signature
end

#localHeaderOffsetObject

Returns the value of attribute localHeaderOffset.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def localHeaderOffset
  @localHeaderOffset
end

#nameObject

Returns the value of attribute name.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def name
  @name
end

#restore_ownershipObject

Returns the value of attribute restore_ownership.



56
57
58
# File 'lib/zip/zip_entry.rb', line 56

def restore_ownership
  @restore_ownership
end

#restore_permissionsObject

Returns the value of attribute restore_permissions.



56
57
58
# File 'lib/zip/zip_entry.rb', line 56

def restore_permissions
  @restore_permissions
end

#restore_timesObject

Returns the value of attribute restore_times.



56
57
58
# File 'lib/zip/zip_entry.rb', line 56

def restore_times
  @restore_times
end

#sizeObject

Returns the value of attribute size.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def size
  @size
end

#unix_gidObject

Returns the value of attribute unix_gid.



57
58
59
# File 'lib/zip/zip_entry.rb', line 57

def unix_gid
  @unix_gid
end

#unix_permsObject

Returns the value of attribute unix_perms.



57
58
59
# File 'lib/zip/zip_entry.rb', line 57

def unix_perms
  @unix_perms
end

#unix_uidObject

Returns the value of attribute unix_uid.



57
58
59
# File 'lib/zip/zip_entry.rb', line 57

def unix_uid
  @unix_uid
end

#zipfileObject

Returns the value of attribute zipfile.



52
53
54
# File 'lib/zip/zip_entry.rb', line 52

def zipfile
  @zipfile
end

Class Method Details

.read_c_dir_entry(io) ⇒ Object

:nodoc:all



211
212
213
214
215
216
217
# File 'lib/zip/zip_entry.rb', line 211

def read_c_dir_entry(io)  #:nodoc:all
  entry = new(io.path)
  entry.read_c_dir_entry(io)
  entry
rescue ZipError
  nil
end

.read_local_entry(io) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/zip/zip_entry.rb', line 219

def read_local_entry(io)
  entry = new(io.path)
  entry.read_local_entry(io)
  entry
rescue ZipError
  nil
end

.read_zip_long(io) ⇒ Object

:nodoc:



207
208
209
# File 'lib/zip/zip_entry.rb', line 207

def read_zip_long(io) # :nodoc:
  io.read(4).unpack('V')[0]
end

.read_zip_short(io) ⇒ Object

:nodoc:



203
204
205
# File 'lib/zip/zip_entry.rb', line 203

def read_zip_short(io) # :nodoc:
  io.read(2).unpack('v')[0]
end

Instance Method Details

#<=>(other) ⇒ Object



474
475
476
# File 'lib/zip/zip_entry.rb', line 474

def <=> (other)
  return to_s <=> other.to_s
end

#==(other) ⇒ Object



461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/zip/zip_entry.rb', line 461

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_sizeObject

:nodoc:all



166
167
168
# File 'lib/zip/zip_entry.rb', line 166

def calculate_local_header_size  #:nodoc:all
  LOCAL_ENTRY_STATIC_HEADER_LENGTH + (@name ?  @name.bytesize : 0) + (@extra ? @extra.local_size : 0)
end

#cdir_header_sizeObject

:nodoc:all



170
171
172
173
# File 'lib/zip/zip_entry.rb', line 170

def cdir_header_size  #:nodoc:all
  CDIR_ENTRY_STATIC_HEADER_LENGTH  + (@name ?  @name.bytesize : 0) +
  (@extra ? @extra.c_dir_size : 0) + (@comment ? @comment.bytesize : 0)
end

#directory?Boolean Also known as: is_directory

Returns true if the entry is a directory.

Returns:

  • (Boolean)

Raises:



140
141
142
143
# File 'lib/zip/zip_entry.rb', line 140

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).



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/zip/zip_entry.rb', line 180

def extract(destPath = @name, &onExistsProc)
  onExistsProc ||= proc { Zip.options[:on_exists_proc] }

  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.

Returns:

  • (Boolean)

Raises:



147
148
149
150
# File 'lib/zip/zip_entry.rb', line 147

def file?
  raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype
  @ftype == :file
end

#file_stat(path) ⇒ Object

:nodoc:



377
378
379
380
381
382
383
# File 'lib/zip/zip_entry.rb', line 377

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:



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
# File 'lib/zip/zip_entry.rb', line 511

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:



385
386
387
388
389
390
391
392
# File 'lib/zip/zip_entry.rb', line 385

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.



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/zip/zip_entry.rb', line 480

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



558
559
560
# File 'lib/zip/zip_entry.rb', line 558

def get_raw_input_stream(&aProc)
  ::File.open(@zipfile, "rb", &aProc)
end

#local_entry_offsetObject

:nodoc:all



162
163
164
# File 'lib/zip/zip_entry.rb', line 162

def local_entry_offset  #:nodoc:all
  localHeaderOffset + @local_header_size
end

#name_is_directory?Boolean

:nodoc:all

Returns:

  • (Boolean)


158
159
160
# File 'lib/zip/zip_entry.rb', line 158

def name_is_directory?  #:nodoc:all
  (%r{\/$} =~ @name) != nil
end

#next_header_offsetObject

:nodoc:all



175
176
177
# File 'lib/zip/zip_entry.rb', line 175

def next_header_offset  #:nodoc:all
  local_entry_offset + self.compressed_size
end

#parent_as_stringObject



552
553
554
555
556
# File 'lib/zip/zip_entry.rb', line 552

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



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/zip/zip_entry.rb', line 300

def read_c_dir_entry(io)  #:nodoc:all
  staticSizedFieldsBuf = io.read(CDIR_ENTRY_STATIC_HEADER_LENGTH)
  unless (staticSizedFieldsBuf.bytesize == 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.bytesize == 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
      #best case guess for whether it is a file or not
      #Otherwise this would be set to unknown and that entry would never be able to extracted
      if name_is_directory?
        @ftype = :directory
      else
        @ftype = :file
      end
    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



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/zip/zip_entry.rb', line 236

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)
  extra              = io.read(extraLength)

  if (extra && extra.bytesize != 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:



394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/zip/zip_entry.rb', line 394

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)
    FileUtils::chmod(@unix_perms & unix_perms_mask, destPath) if (@restore_permissions && @unix_perms)
    FileUtils::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.

Returns:

  • (Boolean)

Raises:



153
154
155
156
# File 'lib/zip/zip_entry.rb', line 153

def symlink?
  raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype
  @ftype == :symlink
end

#timeObject Also known as: mtime



120
121
122
123
124
125
126
127
128
# File 'lib/zip/zip_entry.rb', line 120

def time
  if @extra["UniversalTime"]
    @extra["UniversalTime"].mtime
  else
    # Standard time field in central directory has local time
    # under archive creator. Then, we can't get timezone.
    @time
  end
end

#time=(aTime) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/zip/zip_entry.rb', line 131

def time=(aTime)
  unless @extra.member?("UniversalTime")
    @extra.create("UniversalTime")
  end
  @extra["UniversalTime"].mtime = aTime
  @time = aTime
end

#to_sObject



196
197
198
# File 'lib/zip/zip_entry.rb', line 196

def to_s
  @name
end

#write_c_dir_entry(io) ⇒ Object

:nodoc:all



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/zip/zip_entry.rb', line 409

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
    end

    if (!ft.nil?)
      @externalFileAttributes = (ft << 12 | (@unix_perms & 07777)) << 16
    end
  end

  tmp = [
    @header_signature,
    @version                          , # version of encoding software
    @fstype                           , # filesystem type
    @versionNeededToExtract         , # @versionNeededToExtract           ,
    @gp_flags                                 , # @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.bytesize : 0    ,
    0                                 , # disk number start
    @internalFileAttributes           , # file type (binary=0, text=1)
    @externalFileAttributes           , # native filesystem attributes
    @localHeaderOffset                ,
    @name                             ,
    @extra                            ,
    @comment                          
  ]

  io << tmp.pack('VCCvvvvvVVVvvvvvVV')

  io << @name
  io << (@extra ? @extra.to_c_dir_bin : "")
  io << @comment
end

#write_local_entry(io) ⇒ Object

:nodoc:all



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/zip/zip_entry.rb', line 278

def write_local_entry(io)   #:nodoc:all
  @localHeaderOffset = io.tell

  io <<
  [LOCAL_ENTRY_SIGNATURE    ,
  @versionNeededToExtract , # version needed to extract
  @gp_flags                         , # @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



541
542
543
544
545
546
547
548
549
550
# File 'lib/zip/zip_entry.rb', line 541

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