class Resync::Client::Zip::ZipPackage

A ZIP package of resources or changes, providing access to individual bitstreams based on the included manifest file.

Attributes

manifest[R]

Gets the manifest for the ZIP package. Resources in the manifest are each decorated with a bitstream method that returns the bitstream for that resource. @return [ResourceDumpManifest, ChangeDumpManifest] the manifest

for the ZIP package
zipfile[R]

@return [::Zip::File] the ZIP file wrapped by this package

Public Class Methods

new(zipfile) click to toggle source

Creates a new ZipPackage for the specified file.

@param zipfile [::Zip::File, String] the ZIP file, or a path to it.

# File lib/resync/client/zip/zip_package.rb, line 32
def initialize(zipfile)
  self.zipfile = zipfile
  @bitstreams = {}
end

Public Instance Methods

bitstream_for(resource) click to toggle source

Gets the bitstream for the specified resource. (Note that this does no validation; if the resource is not in the manifest, or the corresponding entry is not in the ZIP file, the behavior of the returned {Bitstream} is undefined.)

@return [Bitstream] a bitstream wrapping the ZIP entry for the

specified resource.
# File lib/resync/client/zip/zip_package.rb, line 47
def bitstream_for(resource)
  @bitstreams[resource] ||= Bitstream.new(zipfile: @zipfile, resource: resource)
end
bitstreams() click to toggle source

Gets all bitstreams declared in the package manifest. @return [Array<Bitstream>] a list of all bitstreams in the package

# File lib/resync/client/zip/zip_package.rb, line 53
def bitstreams
  manifest.resources.to_a.map { |r| bitstream_for(r) }
end

Private Instance Methods

manifest=(value) click to toggle source

Private methods

# File lib/resync/client/zip/zip_package.rb, line 62
def manifest=(value)
  @manifest = value
  manifest.zip_package = self
end
zipfile=(value) click to toggle source
# File lib/resync/client/zip/zip_package.rb, line 67
def zipfile=(value)
  @zipfile = value.is_a?(::Zip::File) ? value : ::Zip::File.open(value)
  manifest_entry = zipfile.find_entry('manifest.xml')
  raise "No manifest.xml found in zipfile #{zipfile.name}" unless manifest_entry
  manifest_stream = manifest_entry.get_input_stream
  self.manifest = XMLParser.parse(manifest_stream)
end