class Resync::Client::Zip::ZipPackage
A ZIP package of resources or changes, providing access to individual bitstreams based on the included manifest file.
Attributes
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
@return [::Zip::File] the ZIP file wrapped by this package
Public Class Methods
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
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
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
Private methods
# File lib/resync/client/zip/zip_package.rb, line 62 def manifest=(value) @manifest = value manifest.zip_package = self end
# 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