Class: Zip::ZipFileSystem::ZipFsFile

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

Defined Under Namespace

Classes: ZipFsStat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappedZip) ⇒ ZipFsFile

Returns a new instance of ZipFsFile.


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

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.


24
25
26
# File 'lib/zip/zipfilesystem.rb', line 24

def dir=(value)
  @dir = value
end

Instance Method Details

#atime(fileName) ⇒ Object


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

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

#basename(fileName) ⇒ Object


244
245
246
# File 'lib/zip/zipfilesystem.rb', line 244

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

#blockdev?(filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def blockdev?(filename)
	false
end

#chardev?(filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def chardev?(filename)
	false
end

#chmod(modeInt, *filenames) ⇒ Object


219
220
221
222
223
224
225
226
# File 'lib/zip/zipfilesystem.rb', line 219

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

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


207
208
209
210
211
212
213
214
215
216
217
# File 'lib/zip/zipfilesystem.rb', line 207

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


275
276
277
278
279
280
281
282
# File 'lib/zip/zipfilesystem.rb', line 275

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


349
350
351
352
353
354
355
356
357
# File 'lib/zip/zipfilesystem.rb', line 349

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

#directory?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#dirname(fileName) ⇒ Object


240
241
242
# File 'lib/zip/zipfilesystem.rb', line 240

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

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

Returns:

  • (Boolean)

152
153
154
# File 'lib/zip/zipfilesystem.rb', line 152

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

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

Returns:

  • (Boolean)

133
134
135
# File 'lib/zip/zipfilesystem.rb', line 133

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

#expand_path(aPath) ⇒ Object


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

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

#file?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

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


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

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

#ftype(fileName) ⇒ Object


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

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

#join(*fragments) ⇒ Object


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

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

Raises:

  • (NotImplementedError)

316
317
318
# File 'lib/zip/zipfilesystem.rb', line 316

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

#mtime(fileName) ⇒ Object


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

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

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


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

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

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


182
183
184
185
186
187
188
189
190
191
# File 'lib/zip/zipfilesystem.rb', line 182

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

#pipeObject

Raises:

  • (NotImplementedError)

320
321
322
# File 'lib/zip/zipfilesystem.rb', line 320

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

#pipe?(filename) ⇒ Boolean

Returns:

  • (Boolean)

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

def pipe?(filename)
	false
end

#popen(*args, &aProc) ⇒ Object


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

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

#read(fileName) ⇒ Object


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

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

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

Returns:

  • (Boolean)

142
143
144
# File 'lib/zip/zipfilesystem.rb', line 142

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

#readlines(fileName) ⇒ Object


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

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

Raises:

  • (NotImplementedError)

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

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

#rename(fileToRename, newName) ⇒ Object


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

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

#setgid?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#setuid?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#size(fileName) ⇒ Object


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

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

#size?(fileName) ⇒ Boolean

nil for not found and nil for directories

Returns:

  • (Boolean)

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

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

#socket?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

def socket?(fileName)
	false
end

#split(fileName) ⇒ Object


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

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

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


324
325
326
327
328
329
# File 'lib/zip/zipfilesystem.rb', line 324

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

#sticky?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

165
166
167
# File 'lib/zip/zipfilesystem.rb', line 165

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

Raises:

  • (NotImplementedError)

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

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

#symlink?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

def symlink?(fileName)
	false
end

#truncate(fileName, len) ⇒ Object

Raises:

  • (StandardError)

173
174
175
# File 'lib/zip/zipfilesystem.rb', line 173

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

#umask(*args) ⇒ Object


169
170
171
# File 'lib/zip/zipfilesystem.rb', line 169

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

#utime(modifiedTime, *fileNames) ⇒ Object


256
257
258
259
260
# File 'lib/zip/zipfilesystem.rb', line 256

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

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

Returns:

  • (Boolean)

147
148
149
# File 'lib/zip/zipfilesystem.rb', line 147

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

#zero?(fileName) ⇒ Boolean

Returns:

  • (Boolean)

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

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