Class: Zip::ZipFileSystem::ZipFsFile
- Inherits:
-
Object
- Object
- Zip::ZipFileSystem::ZipFsFile
- 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
-
#dir ⇒ Object
writeonly
Sets the attribute dir.
Instance Method Summary collapse
- #atime(fileName) ⇒ Object
- #basename(fileName) ⇒ Object
- #blockdev?(filename) ⇒ Boolean
- #chardev?(filename) ⇒ Boolean
- #chmod(modeInt, *filenames) ⇒ Object
- #chown(ownerInt, groupInt, *filenames) ⇒ Object
- #ctime(fileName) ⇒ Object
- #delete(*args) ⇒ Object (also: #unlink)
- #directory?(fileName) ⇒ Boolean
- #dirname(fileName) ⇒ Object
- #executable?(fileName) ⇒ Boolean (also: #executable_real?)
- #exists?(fileName) ⇒ Boolean (also: #exist?, #owned?, #grpowned?)
- #expand_path(aPath) ⇒ Object
- #file?(fileName) ⇒ Boolean
- #foreach(fileName, aSep = $/, &aProc) ⇒ Object
- #ftype(fileName) ⇒ Object
-
#initialize(mappedZip) ⇒ ZipFsFile
constructor
A new instance of ZipFsFile.
- #join(*fragments) ⇒ Object
- #link(fileName, symlinkName) ⇒ Object
- #mtime(fileName) ⇒ Object
- #new(fileName, openMode = "r") ⇒ Object
- #open(fileName, openMode = "r", permissionInt = 0644, &block) ⇒ Object
- #pipe ⇒ Object
- #pipe?(filename) ⇒ Boolean
- #popen(*args, &aProc) ⇒ Object
- #read(fileName) ⇒ Object
- #readable?(fileName) ⇒ Boolean (also: #readable_real?)
- #readlines(fileName) ⇒ Object
- #readlink(fileName) ⇒ Object
- #rename(fileToRename, newName) ⇒ Object
- #setgid?(fileName) ⇒ Boolean
- #setuid?(fileName) ⇒ Boolean
- #size(fileName) ⇒ Object
-
#size?(fileName) ⇒ Boolean
Returns nil for not found and nil for directories.
- #socket?(fileName) ⇒ Boolean
- #split(fileName) ⇒ Object
- #stat(fileName) ⇒ Object (also: #lstat)
- #sticky?(fileName) ⇒ Boolean
- #symlink(fileName, symlinkName) ⇒ Object
- #symlink?(fileName) ⇒ Boolean
- #truncate(fileName, len) ⇒ Object
- #umask(*args) ⇒ Object
- #utime(modifiedTime, *fileNames) ⇒ Object
- #writable?(fileName) ⇒ Boolean (also: #writable_real?)
- #zero?(fileName) ⇒ Boolean
Constructor Details
#initialize(mappedZip) ⇒ ZipFsFile
Returns a new instance of ZipFsFile.
161 162 163 |
# File 'lib/zip/zipfilesystem.rb', line 161 def initialize(mappedZip) @mappedZip = mappedZip end |
Instance Attribute Details
#dir=(value) ⇒ Object (writeonly)
Sets the attribute dir
69 70 71 |
# File 'lib/zip/zipfilesystem.rb', line 69 def dir=(value) @dir = value end |
Instance Method Details
#atime(fileName) ⇒ Object
319 320 321 322 323 324 325 326 |
# File 'lib/zip/zipfilesystem.rb', line 319 def atime(fileName) e = get_entry(fileName) if e.extra.member? "UniversalTime" e.extra["UniversalTime"].atime else nil end end |
#basename(fileName) ⇒ Object
297 298 299 |
# File 'lib/zip/zipfilesystem.rb', line 297 def basename(fileName) ::File.basename(fileName) end |
#blockdev?(filename) ⇒ Boolean
341 342 343 |
# File 'lib/zip/zipfilesystem.rb', line 341 def blockdev?(filename) false end |
#chardev?(filename) ⇒ Boolean
345 346 347 |
# File 'lib/zip/zipfilesystem.rb', line 345 def chardev?(filename) false end |
#chmod(modeInt, *filenames) ⇒ Object
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/zip/zipfilesystem.rb', line 270 def chmod (modeInt, *filenames) filenames.each { |fileName| e = get_entry(fileName) e.fstype = 3 # force convertion filesystem type to unix e.unix_perms = modeInt e.externalFileAttributes = modeInt << 16 e.dirty = true } filenames.size end |
#chown(ownerInt, groupInt, *filenames) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/zip/zipfilesystem.rb', line 258 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 |
#ctime(fileName) ⇒ Object
328 329 330 331 332 333 334 335 |
# File 'lib/zip/zipfilesystem.rb', line 328 def ctime(fileName) e = get_entry(fileName) if e.extra.member? "UniversalTime" e.extra["UniversalTime"].ctime else nil end end |
#delete(*args) ⇒ Object Also known as: unlink
402 403 404 405 406 407 408 409 410 |
# File 'lib/zip/zipfilesystem.rb', line 402 def delete(*args) args.each { |fileName| if directory?(fileName) raise Errno::EISDIR, "Is a directory - \"#{fileName}\"" end @mappedZip.remove(fileName) } end |
#directory?(fileName) ⇒ Boolean
227 228 229 230 |
# File 'lib/zip/zipfilesystem.rb', line 227 def directory?(fileName) entry = @mappedZip.find_entry(fileName) (fileName) == "/" || (entry != nil && entry.directory?) end |
#dirname(fileName) ⇒ Object
293 294 295 |
# File 'lib/zip/zipfilesystem.rb', line 293 def dirname(fileName) ::File.dirname(fileName) end |
#executable?(fileName) ⇒ Boolean Also known as: executable_real?
202 203 204 |
# File 'lib/zip/zipfilesystem.rb', line 202 def executable?(fileName) unix_mode_cmp(fileName, 0111) end |
#exists?(fileName) ⇒ Boolean Also known as: exist?, owned?, grpowned?
183 184 185 |
# File 'lib/zip/zipfilesystem.rb', line 183 def exists?(fileName) (fileName) == "/" || @mappedZip.find_entry(fileName) != nil end |
#expand_path(aPath) ⇒ Object
418 419 420 |
# File 'lib/zip/zipfilesystem.rb', line 418 def (aPath) @mappedZip.(aPath) end |
#file?(fileName) ⇒ Boolean
288 289 290 291 |
# File 'lib/zip/zipfilesystem.rb', line 288 def file?(fileName) entry = @mappedZip.find_entry(fileName) entry != nil && entry.file? end |
#foreach(fileName, aSep = $/, &aProc) ⇒ Object
398 399 400 |
# File 'lib/zip/zipfilesystem.rb', line 398 def foreach(fileName, aSep = $/, &aProc) open(fileName) { |is| is.each_line(aSep, &aProc) } end |
#ftype(fileName) ⇒ Object
357 358 359 |
# File 'lib/zip/zipfilesystem.rb', line 357 def ftype(fileName) @mappedZip.get_entry(fileName).directory? ? "directory" : "file" end |
#join(*fragments) ⇒ Object
305 306 307 |
# File 'lib/zip/zipfilesystem.rb', line 305 def join(*fragments) ::File.join(*fragments) end |
#link(fileName, symlinkName) ⇒ Object
369 370 371 |
# File 'lib/zip/zipfilesystem.rb', line 369 def link(fileName, symlinkName) raise NotImplementedError, "The link() function is not implemented" end |
#mtime(fileName) ⇒ Object
315 316 317 |
# File 'lib/zip/zipfilesystem.rb', line 315 def mtime(fileName) @mappedZip.get_entry(fileName).mtime end |
#new(fileName, openMode = "r") ⇒ Object
244 245 246 |
# File 'lib/zip/zipfilesystem.rb', line 244 def new(fileName, openMode = "r") open(fileName, openMode) end |
#open(fileName, openMode = "r", permissionInt = 0644, &block) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/zip/zipfilesystem.rb', line 232 def open(fileName, openMode = "r", = 0644, &block) openMode.gsub!("b", "") # ignore b option 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 |
#pipe ⇒ Object
373 374 375 |
# File 'lib/zip/zipfilesystem.rb', line 373 def pipe raise NotImplementedError, "The pipe() function is not implemented" end |
#pipe?(filename) ⇒ Boolean
337 338 339 |
# File 'lib/zip/zipfilesystem.rb', line 337 def pipe?(filename) false end |
#popen(*args, &aProc) ⇒ Object
394 395 396 |
# File 'lib/zip/zipfilesystem.rb', line 394 def popen(*args, &aProc) File.popen(*args, &aProc) end |
#read(fileName) ⇒ Object
390 391 392 |
# File 'lib/zip/zipfilesystem.rb', line 390 def read(fileName) @mappedZip.read(fileName) end |
#readable?(fileName) ⇒ Boolean Also known as: readable_real?
192 193 194 |
# File 'lib/zip/zipfilesystem.rb', line 192 def readable?(fileName) unix_mode_cmp(fileName, 0444) end |
#readlines(fileName) ⇒ Object
386 387 388 |
# File 'lib/zip/zipfilesystem.rb', line 386 def readlines(fileName) open(fileName) { |is| is.readlines } end |
#readlink(fileName) ⇒ Object
361 362 363 |
# File 'lib/zip/zipfilesystem.rb', line 361 def readlink(fileName) raise NotImplementedError, "The readlink() function is not implemented" end |
#rename(fileToRename, newName) ⇒ Object
412 413 414 |
# File 'lib/zip/zipfilesystem.rb', line 412 def rename(fileToRename, newName) @mappedZip.rename(fileToRename, newName) { true } end |
#setgid?(fileName) ⇒ Boolean
211 212 213 |
# File 'lib/zip/zipfilesystem.rb', line 211 def setgid?(fileName) unix_mode_cmp(fileName, 02000) end |
#setuid?(fileName) ⇒ Boolean
207 208 209 |
# File 'lib/zip/zipfilesystem.rb', line 207 def setuid?(fileName) unix_mode_cmp(fileName, 04000) end |
#size(fileName) ⇒ Object
248 249 250 |
# File 'lib/zip/zipfilesystem.rb', line 248 def size(fileName) @mappedZip.get_entry(fileName).size end |
#size?(fileName) ⇒ Boolean
Returns nil for not found and nil for directories
253 254 255 256 |
# File 'lib/zip/zipfilesystem.rb', line 253 def size?(fileName) entry = @mappedZip.find_entry(fileName) return (entry == nil || entry.directory?) ? nil : entry.size end |
#socket?(fileName) ⇒ Boolean
353 354 355 |
# File 'lib/zip/zipfilesystem.rb', line 353 def socket?(fileName) false end |
#split(fileName) ⇒ Object
301 302 303 |
# File 'lib/zip/zipfilesystem.rb', line 301 def split(fileName) ::File.split(fileName) end |
#stat(fileName) ⇒ Object Also known as: lstat
377 378 379 380 381 382 |
# File 'lib/zip/zipfilesystem.rb', line 377 def stat(fileName) if ! exists?(fileName) raise Errno::ENOENT, fileName end ZipFsStat.new(self, fileName) end |
#sticky?(fileName) ⇒ Boolean
215 216 217 |
# File 'lib/zip/zipfilesystem.rb', line 215 def sticky?(fileName) unix_mode_cmp(fileName, 01000) end |
#symlink(fileName, symlinkName) ⇒ Object
365 366 367 |
# File 'lib/zip/zipfilesystem.rb', line 365 def symlink(fileName, symlinkName) raise NotImplementedError, "The symlink() function is not implemented" end |
#symlink?(fileName) ⇒ Boolean
349 350 351 |
# File 'lib/zip/zipfilesystem.rb', line 349 def symlink?(fileName) false end |
#truncate(fileName, len) ⇒ Object
223 224 225 |
# File 'lib/zip/zipfilesystem.rb', line 223 def truncate(fileName, len) raise StandardError, "truncate not supported" end |
#umask(*args) ⇒ Object
219 220 221 |
# File 'lib/zip/zipfilesystem.rb', line 219 def umask(*args) ::File.umask(*args) end |
#utime(modifiedTime, *fileNames) ⇒ Object
309 310 311 312 313 |
# File 'lib/zip/zipfilesystem.rb', line 309 def utime(modifiedTime, *fileNames) fileNames.each { |fileName| get_entry(fileName).time = modifiedTime } end |
#writable?(fileName) ⇒ Boolean Also known as: writable_real?
197 198 199 |
# File 'lib/zip/zipfilesystem.rb', line 197 def writable?(fileName) unix_mode_cmp(fileName, 0222) end |
#zero?(fileName) ⇒ Boolean
281 282 283 284 285 286 |
# File 'lib/zip/zipfilesystem.rb', line 281 def zero?(fileName) sz = size(fileName) sz == nil || sz == 0 rescue Errno::ENOENT false end |