Class: Zip::ZipFileSystem::ZipFsFile

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

Overview

Instances of this class are normally accessed via the accessor ZipFile::file. An instance of ZipFsFile behaves like ruby's builtin File (class) object, except it works on ZipFile 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

- (ZipFsFile) initialize(mappedZip)



156
157
158
# File 'lib/zip/zipfilesystem.rb', line 156

def initialize(mappedZip)
	@mappedZip = mappedZip
end

Instance Attribute Details

- (Object) dir=(value) (writeonly)

Sets the attribute dir



69
70
71
# File 'lib/zip/zipfilesystem.rb', line 69

def dir=(value)
  @dir = value
end

Instance Method Details

- (Object) atime(fileName)



311
312
313
314
315
316
317
318
# File 'lib/zip/zipfilesystem.rb', line 311

def atime(fileName)
  e = get_entry(fileName)
  if e.extra.member? "UniversalTime"
    e.extra["UniversalTime"].atime
  else
    nil
  end
end

- (Object) basename(fileName)



289
290
291
# File 'lib/zip/zipfilesystem.rb', line 289

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

- (Boolean) blockdev?(filename)



333
334
335
# File 'lib/zip/zipfilesystem.rb', line 333

def blockdev?(filename)
	false
end

- (Boolean) chardev?(filename)



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

def chardev?(filename)
	false
end

- (Object) chmod(modeInt, *filenames)



264
265
266
267
268
269
270
271
# File 'lib/zip/zipfilesystem.rb', line 264

def chmod (modeInt, *filenames)
  filenames.each { |fileName|
    e = get_entry(fileName)
    e.fstype = 3 # force convertion filesystem type to unix
    e.externalFileAttributes = modeInt << 16
  }
  filenames.size
end

- (Object) chown(ownerInt, groupInt, *filenames)



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

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

- (Object) ctime(fileName)



320
321
322
323
324
325
326
327
# File 'lib/zip/zipfilesystem.rb', line 320

def ctime(fileName)
  e = get_entry(fileName)
  if e.extra.member? "UniversalTime"
    e.extra["UniversalTime"].ctime
  else
    nil
  end
end

- (Object) delete(*args) Also known as: unlink



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

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

- (Boolean) directory?(fileName)



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

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

- (Object) dirname(fileName)



285
286
287
# File 'lib/zip/zipfilesystem.rb', line 285

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

- (Boolean) executable?(fileName) Also known as: executable_real?



197
198
199
# File 'lib/zip/zipfilesystem.rb', line 197

def executable?(fileName)
  unix_mode_cmp(fileName, 0111)
end

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



178
179
180
# File 'lib/zip/zipfilesystem.rb', line 178

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

- (Object) expand_path(aPath)



410
411
412
# File 'lib/zip/zipfilesystem.rb', line 410

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

- (Boolean) file?(fileName)



280
281
282
283
# File 'lib/zip/zipfilesystem.rb', line 280

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

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



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

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

- (Object) ftype(fileName)



349
350
351
# File 'lib/zip/zipfilesystem.rb', line 349

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

- (Object) join(*fragments)



297
298
299
# File 'lib/zip/zipfilesystem.rb', line 297

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

Raises:

  • (NotImplementedError)


361
362
363
# File 'lib/zip/zipfilesystem.rb', line 361

def link(fileName, symlinkName)
	raise NotImplementedError, "The link() function is not implemented"
end

- (Object) mtime(fileName)



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

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

- (Object) new(fileName, openMode = "r"))



238
239
240
# File 'lib/zip/zipfilesystem.rb', line 238

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

- (Object) open(fileName, openMode = "r",, &block)



227
228
229
230
231
232
233
234
235
236
# File 'lib/zip/zipfilesystem.rb', line 227

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

- (Object) pipe

Raises:

  • (NotImplementedError)


365
366
367
# File 'lib/zip/zipfilesystem.rb', line 365

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

- (Boolean) pipe?(filename)



329
330
331
# File 'lib/zip/zipfilesystem.rb', line 329

def pipe?(filename)
	false
end

- (Object) popen(*args, &aProc)



386
387
388
# File 'lib/zip/zipfilesystem.rb', line 386

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

- (Object) read(fileName)



382
383
384
# File 'lib/zip/zipfilesystem.rb', line 382

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

- (Boolean) readable?(fileName) Also known as: readable_real?



187
188
189
# File 'lib/zip/zipfilesystem.rb', line 187

def readable?(fileName)
  unix_mode_cmp(fileName, 0444)
end

- (Object) readlines(fileName)



378
379
380
# File 'lib/zip/zipfilesystem.rb', line 378

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

Raises:

  • (NotImplementedError)


353
354
355
# File 'lib/zip/zipfilesystem.rb', line 353

def readlink(fileName)
	raise NotImplementedError, "The readlink() function is not implemented"
end

- (Object) rename(fileToRename, newName)



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

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

- (Boolean) setgid?(fileName)



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

def setgid?(fileName)
  unix_mode_cmp(fileName, 02000)
end

- (Boolean) setuid?(fileName)



202
203
204
# File 'lib/zip/zipfilesystem.rb', line 202

def setuid?(fileName)
  unix_mode_cmp(fileName, 04000)
end

- (Object) size(fileName)



242
243
244
# File 'lib/zip/zipfilesystem.rb', line 242

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

- (Boolean) size?(fileName)

Returns nil for not found and nil for directories



247
248
249
250
# File 'lib/zip/zipfilesystem.rb', line 247

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

- (Boolean) socket?(fileName)



345
346
347
# File 'lib/zip/zipfilesystem.rb', line 345

def socket?(fileName)
	false
end

- (Object) split(fileName)



293
294
295
# File 'lib/zip/zipfilesystem.rb', line 293

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

- (Object) stat(fileName) Also known as: lstat



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

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

- (Boolean) sticky?(fileName)



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

def sticky?(fileName)
  unix_mode_cmp(fileName, 01000)
end

Raises:

  • (NotImplementedError)


357
358
359
# File 'lib/zip/zipfilesystem.rb', line 357

def symlink(fileName, symlinkName)
	raise NotImplementedError, "The symlink() function is not implemented"
end

- (Boolean) symlink?(fileName)



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

def symlink?(fileName)
	false
end

- (Object) truncate(fileName, len)

Raises:

  • (StandardError)


218
219
220
# File 'lib/zip/zipfilesystem.rb', line 218

def truncate(fileName, len)
  raise StandardError, "truncate not supported"
end

- (Object) umask(*args)



214
215
216
# File 'lib/zip/zipfilesystem.rb', line 214

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

- (Object) utime(modifiedTime, *fileNames)



301
302
303
304
305
# File 'lib/zip/zipfilesystem.rb', line 301

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

- (Boolean) writable?(fileName) Also known as: writable_real?



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

def writable?(fileName)
  unix_mode_cmp(fileName, 0222)
end

- (Boolean) zero?(fileName)



273
274
275
276
277
278
# File 'lib/zip/zipfilesystem.rb', line 273

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