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(mappedZip) ⇒ ZipFsFile

Returns a new instance of ZipFsFile


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

def initialize(mappedZip)
  @mappedZip = mappedZip
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


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

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


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

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

#blockdev?(_filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def blockdev?(_filename)
  false
end

#chardev?(_filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def chardev?(_filename)
  false
end

#chmod(modeInt, *filenames) ⇒ Object


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

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

#chown(ownerInt, groupInt, *filenames) ⇒ Object


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

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

#ctime(fileName) ⇒ Object


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

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


406
407
408
409
410
411
412
413
# File 'lib/zip/filesystem.rb', line 406

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

#directory?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#dirname(fileName) ⇒ Object


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

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

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

Returns:

  • (Boolean)

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

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

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

Returns:

  • (Boolean)

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

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

#expand_path(aPath) ⇒ Object


421
422
423
# File 'lib/zip/filesystem.rb', line 421

def expand_path(aPath)
  @mappedZip.expand_path(aPath)
end

#file?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

def file?(fileName)
  entry = @mappedZip.find_entry(fileName)
  !entry.nil? && entry.file?
end

#foreach(fileName, aSep = $/, &aProc) ⇒ Object


402
403
404
# File 'lib/zip/filesystem.rb', line 402

def foreach(fileName, aSep = $/, &aProc)
  open(fileName) { |is| is.each_line(aSep, &aProc) }
end

#ftype(fileName) ⇒ Object


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

def ftype(fileName)
  @mappedZip.get_entry(fileName).directory? ? 'directory' : 'file'
end

#join(*fragments) ⇒ Object


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

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

Raises:

  • (NotImplementedError)

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

def link(_fileName, _symlinkName)
  raise NotImplementedError, 'The link() function is not implemented'
end

#mtime(fileName) ⇒ Object


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

def mtime(fileName)
  @mappedZip.get_entry(fileName).mtime
end

#new(fileName, openMode = 'r') ⇒ Object


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

def new(fileName, openMode = 'r')
  open(fileName, openMode)
end

#open(fileName, openMode = 'r', permissionInt = 0o644, &block) ⇒ Object


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

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

#pipeObject

Raises:

  • (NotImplementedError)

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

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

#pipe?(_filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def pipe?(_filename)
  false
end

#popen(*args, &aProc) ⇒ Object


398
399
400
# File 'lib/zip/filesystem.rb', line 398

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

#read(fileName) ⇒ Object


394
395
396
# File 'lib/zip/filesystem.rb', line 394

def read(fileName)
  @mappedZip.read(fileName)
end

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

Returns:

  • (Boolean)

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

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

#readlines(fileName) ⇒ Object


390
391
392
# File 'lib/zip/filesystem.rb', line 390

def readlines(fileName)
  open(fileName) { |is| is.readlines }
end

Raises:

  • (NotImplementedError)

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

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

#rename(fileToRename, newName) ⇒ Object


415
416
417
# File 'lib/zip/filesystem.rb', line 415

def rename(fileToRename, newName)
  @mappedZip.rename(fileToRename, newName) { true }
end

#setgid?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#setuid?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#size(fileName) ⇒ Object


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

def size(fileName)
  @mappedZip.get_entry(fileName).size
end

#size?(fileName) ⇒ Boolean

Returns nil for not found and nil for directories

Returns:

  • (Boolean)

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

def size?(fileName)
  entry = @mappedZip.find_entry(fileName)
  entry.nil? || entry.directory? ? nil : entry.size
end

#socket?(_fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

def socket?(_fileName)
  false
end

#split(fileName) ⇒ Object


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

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

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

Raises:

  • (Errno::ENOENT)

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

def stat(fileName)
  raise Errno::ENOENT, fileName unless exists?(fileName)
  ZipFsStat.new(self, fileName)
end

#sticky?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

Raises:

  • (NotImplementedError)

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

def symlink(_fileName, _symlinkName)
  raise NotImplementedError, 'The symlink() function is not implemented'
end

#symlink?(_fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

def symlink?(_fileName)
  false
end

#truncate(_fileName, _len) ⇒ Object

Raises:

  • (StandardError)

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

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

#umask(*args) ⇒ Object


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

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

#utime(modifiedTime, *fileNames) ⇒ Object


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

def utime(modifiedTime, *fileNames)
  fileNames.each do |fileName|
    get_entry(fileName).time = modifiedTime
  end
end

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

Returns:

  • (Boolean)

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

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

#zero?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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