Class: Zip::FileSystem::ZipFsFile

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

Overview

Instances of this class are normally accessed via the accessor Zip::File::file. An instance of ZipFsFile behaves like ruby’s builtin File (class) object, except it works on Zip::File entries.

The individual methods are not documented due to their similarity with the methods in File

Defined Under Namespace

Classes: ZipFsStat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapped_zip) ⇒ ZipFsFile

Returns a new instance of ZipFsFile.



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

def initialize(mapped_zip)
  @mapped_zip = mapped_zip
end

Instance Attribute Details

#dir=(value) ⇒ Object (writeonly)

Sets the attribute dir

Parameters:

  • value

    the value to set the attribute dir to.



66
67
68
# File 'lib/zip/filesystem.rb', line 66

def dir=(value)
  @dir = value
end

Instance Method Details

#atime(filename) ⇒ Object



326
327
328
329
330
331
332
333
# File 'lib/zip/filesystem.rb', line 326

def atime(filename)
  e = get_entry(filename)
  if e.extra.member? 'UniversalTime'
    e.extra['UniversalTime'].atime
  elsif e.extra.member? 'NTFS'
    e.extra['NTFS'].atime
  end
end

#basename(filename) ⇒ Object



304
305
306
# File 'lib/zip/filesystem.rb', line 304

def basename(filename)
  ::File.basename(filename)
end

#blockdev?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


348
349
350
# File 'lib/zip/filesystem.rb', line 348

def blockdev?(_filename)
  false
end

#chardev?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


352
353
354
# File 'lib/zip/filesystem.rb', line 352

def chardev?(_filename)
  false
end

#chmod(mode, *filenames) ⇒ Object



277
278
279
280
281
282
283
284
285
286
# File 'lib/zip/filesystem.rb', line 277

def chmod(mode, *filenames)
  filenames.each do |filename|
    e = get_entry(filename)
    e.fstype = 3 # force convertion filesystem type to unix
    e.unix_perms = mode
    e.external_file_attributes = mode << 16
    e.dirty = true
  end
  filenames.size
end

#chown(owner, group, *filenames) ⇒ Object



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

def chown(owner, group, *filenames)
  filenames.each do |filename|
    e = get_entry(filename)
    e.extra.create('IUnix') unless e.extra.member?('IUnix')
    e.extra['IUnix'].uid = owner
    e.extra['IUnix'].gid = group
  end
  filenames.size
end

#ctime(filename) ⇒ Object



335
336
337
338
339
340
341
342
# File 'lib/zip/filesystem.rb', line 335

def ctime(filename)
  e = get_entry(filename)
  if e.extra.member? 'UniversalTime'
    e.extra['UniversalTime'].ctime
  elsif e.extra.member? 'NTFS'
    e.extra['NTFS'].ctime
  end
end

#delete(*args) ⇒ Object Also known as: unlink



408
409
410
411
412
413
414
415
416
# File 'lib/zip/filesystem.rb', line 408

def delete(*args)
  args.each do |filename|
    if directory?(filename)
      raise Errno::EISDIR, "Is a directory - \"#{filename}\""
    end

    @mapped_zip.remove(filename)
  end
end

#directory?(filename) ⇒ Boolean

Returns:

  • (Boolean)


236
237
238
239
# File 'lib/zip/filesystem.rb', line 236

def directory?(filename)
  entry = @mapped_zip.find_entry(filename)
  expand_path(filename) == '/' || (!entry.nil? && entry.directory?)
end

#dirname(filename) ⇒ Object



300
301
302
# File 'lib/zip/filesystem.rb', line 300

def dirname(filename)
  ::File.dirname(filename)
end

#executable?(filename) ⇒ Boolean Also known as: executable_real?

Returns:

  • (Boolean)


211
212
213
# File 'lib/zip/filesystem.rb', line 211

def executable?(filename)
  unix_mode_cmp(filename, 0o111)
end

#exists?(filename) ⇒ Boolean Also known as: exist?, owned?, grpowned?

Returns:

  • (Boolean)


192
193
194
# File 'lib/zip/filesystem.rb', line 192

def exists?(filename)
  expand_path(filename) == '/' || !@mapped_zip.find_entry(filename).nil?
end

#expand_path(path) ⇒ Object



424
425
426
# File 'lib/zip/filesystem.rb', line 424

def expand_path(path)
  @mapped_zip.expand_path(path)
end

#file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
298
# File 'lib/zip/filesystem.rb', line 295

def file?(filename)
  entry = @mapped_zip.find_entry(filename)
  !entry.nil? && entry.file?
end

#foreach(filename, sep = $INPUT_RECORD_SEPARATOR, &a_proc) ⇒ Object



404
405
406
# File 'lib/zip/filesystem.rb', line 404

def foreach(filename, sep = $INPUT_RECORD_SEPARATOR, &a_proc)
  self.open(filename) { |is| is.each_line(sep, &a_proc) }
end

#ftype(filename) ⇒ Object



364
365
366
# File 'lib/zip/filesystem.rb', line 364

def ftype(filename)
  @mapped_zip.get_entry(filename).directory? ? 'directory' : 'file'
end

#join(*fragments) ⇒ Object



312
313
314
# File 'lib/zip/filesystem.rb', line 312

def join(*fragments)
  ::File.join(*fragments)
end

Raises:

  • (NotImplementedError)


376
377
378
# File 'lib/zip/filesystem.rb', line 376

def link(_filename, _symlink_name)
  raise NotImplementedError, 'The link() function is not implemented'
end

#mtime(filename) ⇒ Object



322
323
324
# File 'lib/zip/filesystem.rb', line 322

def mtime(filename)
  @mapped_zip.get_entry(filename).mtime
end

#new(filename, mode = 'r') ⇒ Object



253
254
255
# File 'lib/zip/filesystem.rb', line 253

def new(filename, mode = 'r')
  self.open(filename, mode)
end

#open(filename, mode = 'r', permissions = 0o644, &block) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
# File 'lib/zip/filesystem.rb', line 241

def open(filename, mode = 'r', permissions = 0o644, &block)
  mode.delete!('b') # ignore b option
  case mode
  when 'r'
    @mapped_zip.get_input_stream(filename, &block)
  when 'w'
    @mapped_zip.get_output_stream(filename, permissions, &block)
  else
    raise StandardError, "openmode '#{mode} not supported" unless mode == 'r'
  end
end

#pipeObject

Raises:

  • (NotImplementedError)


380
381
382
# File 'lib/zip/filesystem.rb', line 380

def pipe
  raise NotImplementedError, 'The pipe() function is not implemented'
end

#pipe?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


344
345
346
# File 'lib/zip/filesystem.rb', line 344

def pipe?(_filename)
  false
end

#popen(*args, &a_proc) ⇒ Object



400
401
402
# File 'lib/zip/filesystem.rb', line 400

def popen(*args, &a_proc)
  ::File.popen(*args, &a_proc)
end

#read(filename) ⇒ Object



396
397
398
# File 'lib/zip/filesystem.rb', line 396

def read(filename)
  @mapped_zip.read(filename)
end

#readable?(filename) ⇒ Boolean Also known as: readable_real?

Returns:

  • (Boolean)


201
202
203
# File 'lib/zip/filesystem.rb', line 201

def readable?(filename)
  unix_mode_cmp(filename, 0o444)
end

#readlines(filename) ⇒ Object



392
393
394
# File 'lib/zip/filesystem.rb', line 392

def readlines(filename)
  self.open(filename, &:readlines)
end

Raises:

  • (NotImplementedError)


368
369
370
# File 'lib/zip/filesystem.rb', line 368

def readlink(_filename)
  raise NotImplementedError, 'The readlink() function is not implemented'
end

#rename(file_to_rename, new_name) ⇒ Object



418
419
420
# File 'lib/zip/filesystem.rb', line 418

def rename(file_to_rename, new_name)
  @mapped_zip.rename(file_to_rename, new_name) { true }
end

#setgid?(filename) ⇒ Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/zip/filesystem.rb', line 220

def setgid?(filename)
  unix_mode_cmp(filename, 0o2000)
end

#setuid?(filename) ⇒ Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/zip/filesystem.rb', line 216

def setuid?(filename)
  unix_mode_cmp(filename, 0o4000)
end

#size(filename) ⇒ Object



257
258
259
# File 'lib/zip/filesystem.rb', line 257

def size(filename)
  @mapped_zip.get_entry(filename).size
end

#size?(filename) ⇒ Boolean

Returns nil for not found and nil for directories

Returns:

  • (Boolean)


262
263
264
265
# File 'lib/zip/filesystem.rb', line 262

def size?(filename)
  entry = @mapped_zip.find_entry(filename)
  entry.nil? || entry.directory? ? nil : entry.size
end

#socket?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


360
361
362
# File 'lib/zip/filesystem.rb', line 360

def socket?(_filename)
  false
end

#split(filename) ⇒ Object



308
309
310
# File 'lib/zip/filesystem.rb', line 308

def split(filename)
  ::File.split(filename)
end

#stat(filename) ⇒ Object Also known as: lstat

Raises:

  • (Errno::ENOENT)


384
385
386
387
388
# File 'lib/zip/filesystem.rb', line 384

def stat(filename)
  raise Errno::ENOENT, filename unless exists?(filename)

  ZipFsStat.new(self, filename)
end

#sticky?(filename) ⇒ Boolean

Returns:

  • (Boolean)


224
225
226
# File 'lib/zip/filesystem.rb', line 224

def sticky?(filename)
  unix_mode_cmp(filename, 0o1000)
end

Raises:

  • (NotImplementedError)


372
373
374
# File 'lib/zip/filesystem.rb', line 372

def symlink(_filename, _symlink_name)
  raise NotImplementedError, 'The symlink() function is not implemented'
end

#symlink?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


356
357
358
# File 'lib/zip/filesystem.rb', line 356

def symlink?(_filename)
  false
end

#truncate(_filename, _len) ⇒ Object

Raises:

  • (StandardError)


232
233
234
# File 'lib/zip/filesystem.rb', line 232

def truncate(_filename, _len)
  raise StandardError, 'truncate not supported'
end

#umask(*args) ⇒ Object



228
229
230
# File 'lib/zip/filesystem.rb', line 228

def umask(*args)
  ::File.umask(*args)
end

#utime(modified_time, *filenames) ⇒ Object



316
317
318
319
320
# File 'lib/zip/filesystem.rb', line 316

def utime(modified_time, *filenames)
  filenames.each do |filename|
    get_entry(filename).time = modified_time
  end
end

#writable?(filename) ⇒ Boolean Also known as: writable_real?

Returns:

  • (Boolean)


206
207
208
# File 'lib/zip/filesystem.rb', line 206

def writable?(filename)
  unix_mode_cmp(filename, 0o222)
end

#zero?(filename) ⇒ Boolean

Returns:

  • (Boolean)


288
289
290
291
292
293
# File 'lib/zip/filesystem.rb', line 288

def zero?(filename)
  sz = size(filename)
  sz.nil? || sz == 0
rescue Errno::ENOENT
  false
end