Class: Zip::Entry

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

Direct Known Subclasses

StreamableDirectory, StreamableStream

Constant Summary collapse

STORED =
0
DEFLATED =
8
EFS =

Language encoding flag (EFS) bit

0b100000000000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Entry

Returns a new instance of Entry.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zip/entry.rb', line 52

def initialize(*args)
  name = args[1] || ''
  check_name(name)

  set_default_vars_values
  @fstype = ::Zip::RUNNING_ON_WINDOWS ? ::Zip::FSTYPE_FAT : ::Zip::FSTYPE_UNIX

  @zipfile            = args[0] || ''
  @name               = name
  @comment            = args[2] || ''
  @extra              = args[3] || ''
  @compressed_size    = args[4] || 0
  @crc                = args[5] || 0
  @compression_method = args[6] || ::Zip::Entry::DEFLATED
  @size               = args[7] || 0
  @time               = args[8] || ::Zip::DOSTime.now

  @ftype = name_is_directory? ? :directory : :file
  @extra = ::Zip::ExtraField.new(@extra.to_s) unless @extra.is_a?(::Zip::ExtraField)
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

#compressed_sizeObject

Returns the value of attribute compressed_size.



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

def compressed_size
  @compressed_size
end

#compression_methodObject

Returns the value of attribute compression_method.



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

def compression_method
  @compression_method
end

#crcObject

Returns the value of attribute crc.



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

def crc
  @crc
end

#dirtyObject

Returns the value of attribute dirty.



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

def dirty
  @dirty
end

#external_file_attributesObject

Returns the value of attribute external_file_attributes.



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

def external_file_attributes
  @external_file_attributes
end

#extraObject

Returns the value of attribute extra.



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

def extra
  @extra
end

#filepathObject (readonly)

:nodoc:



14
15
16
# File 'lib/zip/entry.rb', line 14

def filepath
  @filepath
end

Returns the value of attribute follow_symlinks.



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

def follow_symlinks
  @follow_symlinks
end

#fstypeObject

Returns the value of attribute fstype.



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

def fstype
  @fstype
end

#ftypeObject (readonly)

:nodoc:



14
15
16
# File 'lib/zip/entry.rb', line 14

def ftype
  @ftype
end

#gp_flagsObject

Returns the value of attribute gp_flags.



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

def gp_flags
  @gp_flags
end

#header_signatureObject

Returns the value of attribute header_signature.



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

def header_signature
  @header_signature
end

#local_header_offsetObject

Returns the value of attribute local_header_offset.



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

def local_header_offset
  @local_header_offset
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#restore_ownershipObject

Returns the value of attribute restore_ownership.



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

def restore_ownership
  @restore_ownership
end

#restore_permissionsObject

Returns the value of attribute restore_permissions.



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

def restore_permissions
  @restore_permissions
end

#restore_timesObject

Returns the value of attribute restore_times.



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

def restore_times
  @restore_times
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#unix_gidObject

Returns the value of attribute unix_gid.



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

def unix_gid
  @unix_gid
end

#unix_permsObject

Returns the value of attribute unix_perms.



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

def unix_perms
  @unix_perms
end

#unix_uidObject

Returns the value of attribute unix_uid.



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

def unix_uid
  @unix_uid
end

#zipfileObject

Returns the value of attribute zipfile.



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

def zipfile
  @zipfile
end

Class Method Details

.read_c_dir_entry(io) ⇒ Object

:nodoc:all



178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/zip/entry.rb', line 178

def read_c_dir_entry(io) #:nodoc:all
  path = if io.respond_to?(:path)
           io.path
         else
           io
         end
  entry = new(path)
  entry.read_c_dir_entry(io)
  entry
rescue Error
  nil
end

.read_local_entry(io) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/zip/entry.rb', line 191

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

.read_zip_64_long(io) ⇒ Object

:nodoc:



174
175
176
# File 'lib/zip/entry.rb', line 174

def read_zip_64_long(io) # :nodoc:
  io.read(8).unpack('Q<')[0]
end

.read_zip_long(io) ⇒ Object

:nodoc:



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

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

.read_zip_short(io) ⇒ Object

:nodoc:



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

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

Instance Method Details

#<=>(other) ⇒ Object



467
468
469
# File 'lib/zip/entry.rb', line 467

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

#==(other) ⇒ Object



458
459
460
461
462
463
464
465
# File 'lib/zip/entry.rb', line 458

def ==(other)
  return false unless other.class == self.class
  # Compares contents of local entry and exposed fields
  keys_equal = %w(compression_method crc compressed_size size name extra filepath).all? do |k|
    other.__send__(k.to_sym) == __send__(k.to_sym)
  end
  keys_equal && time.dos_equals(other.time)
end

#calculate_local_header_sizeObject

:nodoc:all



127
128
129
# File 'lib/zip/entry.rb', line 127

def calculate_local_header_size #:nodoc:all
  LOCAL_ENTRY_STATIC_HEADER_LENGTH + name_size + extra_size
end

#cdir_header_sizeObject

:nodoc:all



139
140
141
142
# File 'lib/zip/entry.rb', line 139

def cdir_header_size #:nodoc:all
  CDIR_ENTRY_STATIC_HEADER_LENGTH + name_size +
    (@extra ? @extra.c_dir_size : 0) + comment_size
end

#check_c_dir_entry_comment_sizeObject

Raises:



341
342
343
344
# File 'lib/zip/entry.rb', line 341

def check_c_dir_entry_comment_size
  return if @comment && @comment.bytesize == @comment_length
  raise ::Zip::Error, 'Truncated cdir zip entry header'
end

#check_c_dir_entry_signatureObject

Raises:



336
337
338
339
# File 'lib/zip/entry.rb', line 336

def check_c_dir_entry_signature
  return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE
  raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
end

#check_c_dir_entry_static_header_length(buf) ⇒ Object

Raises:



331
332
333
334
# File 'lib/zip/entry.rb', line 331

def check_c_dir_entry_static_header_length(buf)
  return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
  raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
end

#check_name(name) ⇒ Object



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

def check_name(name)
  return unless name.start_with?('/')
  raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
end

#clean_upObject



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

def clean_up
  # By default, do nothing
end

#comment_sizeObject



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

def comment_size
  @comment ? @comment.bytesize : 0
end

#extra_sizeObject



119
120
121
# File 'lib/zip/entry.rb', line 119

def extra_size
  @extra ? @extra.local_size : 0
end

#extract(dest_path = @name, &block) ⇒ Object

Extracts entry to file dest_path (defaults to @name).



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/zip/entry.rb', line 149

def extract(dest_path = @name, &block)
  block ||= proc { ::Zip.on_exists_proc }

  if directory? || file? || symlink?
    __send__("create_#{@ftype}", dest_path, &block)
  else
    raise "unknown file type #{inspect}"
  end

  self
end

#file_stat(path) ⇒ Object

:nodoc:



368
369
370
371
372
373
374
# File 'lib/zip/entry.rb', line 368

def file_stat(path) # :nodoc:
  if @follow_symlinks
    ::File.stat(path)
  else
    ::File.lstat(path)
  end
end

#file_type_is?(type) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



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

def file_type_is?(type)
  raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
  @ftype == type
end

#gather_fileinfo_from_srcpath(src_path) ⇒ Object

:nodoc:



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

def gather_fileinfo_from_srcpath(src_path) # :nodoc:
  stat   = file_stat(src_path)
  @ftype = case stat.ftype
           when 'file'
             if name_is_directory?
               raise ArgumentError,
                     "entry name '#{newEntry}' indicates directory entry, but " \
                         "'#{src_path}' is not a directory"
             end
             :file
           when 'directory'
             @name += '/' unless name_is_directory?
             :directory
           when 'link'
             if name_is_directory?
               raise ArgumentError,
                     "entry name '#{newEntry}' indicates directory entry, but " \
                         "'#{src_path}' is not a directory"
             end
             :symlink
           else
             raise "unknown file type: #{src_path.inspect} #{stat.inspect}"
           end

  @filepath = src_path
  get_extra_attributes_from_path(@filepath)
end

#get_extra_attributes_from_path(path) ⇒ Object

:nodoc:



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

def get_extra_attributes_from_path(path) # :nodoc:
  return if Zip::RUNNING_ON_WINDOWS
  stat        = file_stat(path)
  @unix_uid   = stat.uid
  @unix_gid   = stat.gid
  @unix_perms = stat.mode & 07777
end

#get_input_stream(&block) ⇒ Object

Returns an IO like object for the given ZipEntry. Warning: may behave weird with symlinks.



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/zip/entry.rb', line 473

def get_input_stream(&block)
  if @ftype == :directory
    yield ::Zip::NullInputStream if block_given?
    ::Zip::NullInputStream
  elsif @filepath
    case @ftype
    when :file
      ::File.open(@filepath, 'rb', &block)
    when :symlink
      linkpath = ::File.readlink(@filepath)
      stringio = ::StringIO.new(linkpath)
      yield(stringio) if block_given?
      stringio
    else
      raise "unknown @file_type #{@ftype}"
    end
  else
    zis = ::Zip::InputStream.new(@zipfile, local_header_offset)
    zis.instance_variable_set(:@internal, true)
    zis.get_next_entry
    if block_given?
      begin
        yield(zis)
      ensure
        zis.close
      end
    else
      zis
    end
  end
end

#get_raw_input_stream(&block) ⇒ Object



550
551
552
553
554
555
556
# File 'lib/zip/entry.rb', line 550

def get_raw_input_stream(&block)
  if @zipfile.respond_to?(:seek) && @zipfile.respond_to?(:read)
    yield @zipfile
  else
    ::File.open(@zipfile, 'rb', &block)
  end
end

#local_entry_offsetObject

:nodoc:all



111
112
113
# File 'lib/zip/entry.rb', line 111

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

#name_is_directory?Boolean

:nodoc:all

Returns:

  • (Boolean)


107
108
109
# File 'lib/zip/entry.rb', line 107

def name_is_directory? #:nodoc:all
  @name.end_with?('/')
end

#name_sizeObject



115
116
117
# File 'lib/zip/entry.rb', line 115

def name_size
  @name ? @name.bytesize : 0
end

#next_header_offsetObject

:nodoc:all



144
145
146
# File 'lib/zip/entry.rb', line 144

def next_header_offset #:nodoc:all
  local_entry_offset + compressed_size + data_descriptor_size
end

#pack_c_dir_entryObject



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/zip/entry.rb', line 403

def pack_c_dir_entry
  zip64 = @extra['Zip64']
  [
    @header_signature,
    @version, # version of encoding software
    @fstype, # filesystem type
    @version_needed_to_extract, # @versionNeededToExtract           ,
    @gp_flags, # @gp_flags                          ,
    @compression_method,
    @time.to_binary_dos_time, # @last_mod_time                      ,
    @time.to_binary_dos_date, # @last_mod_date                      ,
    @crc,
    (zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
    (zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
    name_size,
    @extra ? @extra.c_dir_size : 0,
    comment_size,
    (zip64 && zip64.disk_start_number) ? 0xFFFF : 0, # disk number start
    @internal_file_attributes, # file type (binary=0, text=1)
    @external_file_attributes, # native filesystem attributes
    (zip64 && zip64.relative_header_offset) ? 0xFFFFFFFF : @local_header_offset,
    @name,
    @extra,
    @comment
  ].pack('VCCvvvvvVVVvvvvvVV')
end

#pack_local_entryObject



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/zip/entry.rb', line 251

def pack_local_entry
  zip64 = @extra['Zip64']
  [::Zip::LOCAL_ENTRY_SIGNATURE,
   @version_needed_to_extract, # version needed to extract
   @gp_flags, # @gp_flags                  ,
   @compression_method,
   @time.to_binary_dos_time, # @last_mod_time              ,
   @time.to_binary_dos_date, # @last_mod_date              ,
   @crc,
   (zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
   (zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
   name_size,
   @extra ? @extra.local_size : 0].pack('VvvvvvVVVvv')
end

#parent_as_stringObject



544
545
546
547
548
# File 'lib/zip/entry.rb', line 544

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



354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/zip/entry.rb', line 354

def read_c_dir_entry(io) #:nodoc:all
  static_sized_fields_buf = io.read(::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH)
  check_c_dir_entry_static_header_length(static_sized_fields_buf)
  unpack_c_dir_entry(static_sized_fields_buf)
  check_c_dir_entry_signature
  set_time(@last_mod_date, @last_mod_time)
  @name = io.read(@name_length).tr('\\', '/')
  read_c_dir_extra_field(io)
  @comment = io.read(@comment_length)
  check_c_dir_entry_comment_size
  set_ftype_from_c_dir_entry
  parse_zip64_extra(false)
end

#read_c_dir_extra_field(io) ⇒ Object



346
347
348
349
350
351
352
# File 'lib/zip/entry.rb', line 346

def read_c_dir_extra_field(io)
  if @extra.is_a?(::Zip::ExtraField)
    @extra.merge(io.read(@extra_length))
  else
    @extra = ::Zip::ExtraField.new(io.read(@extra_length))
  end
end

#read_local_entry(io) ⇒ Object

:nodoc:all



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/zip/entry.rb', line 217

def read_local_entry(io) #:nodoc:all
  @local_header_offset = io.tell

  static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''

  unless static_sized_fields_buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH
    raise Error, 'Premature end of file. Not enough data for zip entry local header'
  end

  unpack_local_entry(static_sized_fields_buf)

  unless @header_signature == ::Zip::LOCAL_ENTRY_SIGNATURE
    raise ::Zip::Error, "Zip local header magic not found at location '#{local_header_offset}'"
  end
  set_time(@last_mod_date, @last_mod_time)

  @name = io.read(@name_length)
  extra = io.read(@extra_length)

  @name.gsub!('\\', '/')

  if extra && extra.bytesize != @extra_length
    raise ::Zip::Error, 'Truncated local zip entry header'
  else
    if @extra.is_a?(::Zip::ExtraField)
      @extra.merge(extra) if extra
    else
      @extra = ::Zip::ExtraField.new(extra)
    end
  end
  parse_zip64_extra(true)
  @local_header_size = calculate_local_header_size
end

#set_default_vars_valuesObject



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

def set_default_vars_values
  @local_header_offset      = 0
  @local_header_size        = nil # not known until local entry is created or read
  @internal_file_attributes = 1
  @external_file_attributes = 0
  @header_signature         = ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE

  @version_needed_to_extract = VERSION_NEEDED_TO_EXTRACT
  @version                   = VERSION_MADE_BY

  @ftype           = nil          # unspecified or unknown
  @filepath        = nil
  @gp_flags        = 0
  if ::Zip.unicode_names
    @gp_flags |= EFS
    @version = 63
  end
  @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
  @dirty               = false
end

#set_extra_attributes_on_path(dest_path) ⇒ Object

:nodoc:



394
395
396
397
398
399
400
401
# File 'lib/zip/entry.rb', line 394

def set_extra_attributes_on_path(dest_path) # :nodoc:
  return unless file? || directory?

  case @fstype
  when ::Zip::FSTYPE_UNIX
    set_unix_permissions_on_path(dest_path)
  end
end

#set_ftype_from_c_dir_entryObject



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

def set_ftype_from_c_dir_entry
  @ftype = case @fstype
           when ::Zip::FSTYPE_UNIX
             @unix_perms = (@external_file_attributes >> 16) & 07777
             case (@external_file_attributes >> 28)
             when ::Zip::FILE_TYPE_DIR
               :directory
             when ::Zip::FILE_TYPE_FILE
               :file
             when ::Zip::FILE_TYPE_SYMLINK
               :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?
                 :directory
               else
                 :file
               end
             end
           else
             if name_is_directory?
               :directory
             else
               :file
             end
           end
end

#set_unix_permissions_on_path(dest_path) ⇒ Object



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

def set_unix_permissions_on_path(dest_path)
  # 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, dest_path) if @restore_permissions && @unix_perms
  ::FileUtils.chown(@unix_uid, @unix_gid, dest_path) if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0
  # File::utimes()
end

#timeObject Also known as: mtime



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/zip/entry.rb', line 73

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

#time=(value) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/zip/entry.rb', line 87

def time=(value)
  unless @extra.member?('UniversalTime') || @extra.member?('NTFS')
    @extra.create('UniversalTime')
  end
  (@extra['UniversalTime'] || @extra['NTFS']).mtime = value
  @time                         = value
end

#to_sObject



161
162
163
# File 'lib/zip/entry.rb', line 161

def to_s
  @name
end

#unpack_c_dir_entry(buf) ⇒ Object



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

def unpack_c_dir_entry(buf)
  @header_signature,
    @version, # version of encoding software
    @fstype, # filesystem type
    @version_needed_to_extract,
    @gp_flags,
    @compression_method,
    @last_mod_time,
    @last_mod_date,
    @crc,
    @compressed_size,
    @size,
    @name_length,
    @extra_length,
    @comment_length,
    _, # diskNumberStart
    @internal_file_attributes,
    @external_file_attributes,
    @local_header_offset,
    @name,
    @extra,
    @comment = buf.unpack('VCCvvvvvVVVvvvvvVV')
end

#unpack_local_entry(buf) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/zip/entry.rb', line 202

def unpack_local_entry(buf)
  @header_signature,
    @version,
    @fstype,
    @gp_flags,
    @compression_method,
    @last_mod_time,
    @last_mod_date,
    @crc,
    @compressed_size,
    @size,
    @name_length,
    @extra_length = buf.unpack('VCCvvvvVVVvv')
end

#verify_local_header_size!Object

check before rewriting an entry (after file sizes are known) that we didn’t change the header size (and thus clobber file data or something)

Raises:



133
134
135
136
137
# File 'lib/zip/entry.rb', line 133

def verify_local_header_size!
  return if @local_header_size.nil?
  new_size = calculate_local_header_size
  raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size
end

#write_c_dir_entry(io) ⇒ Object

:nodoc:all



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

def write_c_dir_entry(io) #:nodoc:all
  prep_zip64_extra(false)
  case @fstype
  when ::Zip::FSTYPE_UNIX
    ft = case @ftype
         when :file
           @unix_perms ||= 0644
           ::Zip::FILE_TYPE_FILE
         when :directory
           @unix_perms ||= 0755
           ::Zip::FILE_TYPE_DIR
         when :symlink
           @unix_perms ||= 0755
           ::Zip::FILE_TYPE_SYMLINK
         end

    unless ft.nil?
      @external_file_attributes = (ft << 12 | (@unix_perms & 07777)) << 16
    end
  end

  io << pack_c_dir_entry

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

#write_local_entry(io, rewrite = false) ⇒ Object

:nodoc:all



266
267
268
269
270
271
272
273
274
275
276
# File 'lib/zip/entry.rb', line 266

def write_local_entry(io, rewrite = false) #:nodoc:all
  prep_zip64_extra(true)
  verify_local_header_size! if rewrite
  @local_header_offset = io.tell

  io << pack_local_entry

  io << @name
  io << @extra.to_local_bin if @extra
  @local_header_size = io.tell - @local_header_offset
end

#write_to_zip_output_stream(zip_output_stream) ⇒ Object

:nodoc:all



533
534
535
536
537
538
539
540
541
542
# File 'lib/zip/entry.rb', line 533

def write_to_zip_output_stream(zip_output_stream) #:nodoc:all
  if @ftype == :directory
    zip_output_stream.put_next_entry(self, nil, nil, ::Zip::Entry::STORED)
  elsif @filepath
    zip_output_stream.put_next_entry(self, nil, nil, compression_method || ::Zip::Entry::DEFLATED)
    get_input_stream { |is| ::Zip::IOExtras.copy_stream(zip_output_stream, is) }
  else
    zip_output_stream.copy_raw_entry(self)
  end
end