Class: Rack::Archive::Zip::Extract::ExtractedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/archive/zip/extract.rb

Constant Summary collapse

BUFFER_SIZE =
8192

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive, path, buffer_size = BUFFER_SIZE) ⇒ ExtractedFile

Returns a new instance of ExtractedFile.

Parameters:

  • archive (Zip::Archive)
  • path (String)
  • buffer_size (Integer) (defaults to: BUFFER_SIZE)

Raises:

  • ArgumentError when archive already closed



134
135
136
137
138
139
140
141
142
# File 'lib/rack/archive/zip/extract.rb', line 134

def initialize(archive, path, buffer_size=BUFFER_SIZE)
  raise ArgumentError, 'archive already closed' unless archive.open?
  @archive = archive
  @file = @archive.fopen(path)
  @mtime = @file.mtime
  @size = @file.size
  @etag = Digest::MD5.hexdigest(@file.name) + @mtime.to_i.to_s(16) + @size.to_s(16)
  @buffer_size = buffer_size
end

Instance Attribute Details

#etagObject (readonly)

Returns the value of attribute etag.



128
129
130
# File 'lib/rack/archive/zip/extract.rb', line 128

def etag
  @etag
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



128
129
130
# File 'lib/rack/archive/zip/extract.rb', line 128

def mtime
  @mtime
end

#sizeObject (readonly)

Returns the value of attribute size.



128
129
130
# File 'lib/rack/archive/zip/extract.rb', line 128

def size
  @size
end

Instance Method Details

#closeObject



150
151
152
153
# File 'lib/rack/archive/zip/extract.rb', line 150

def close
  @file.close
  @archive.close
end

#eachObject



144
145
146
147
148
# File 'lib/rack/archive/zip/extract.rb', line 144

def each
  while chunk = @file.read(@buffer_size)
    yield chunk
  end
end