Class: Resync::Client::Zip::ZipPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/resync/client/zip/zip_package.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipfile) ⇒ ZipPackage

Creates a new ZipPackage for the specified file.

Parameters:

  • zipfile (::Zip::File, String)

    the ZIP file, or a path to it.



32
33
34
35
# File 'lib/resync/client/zip/zip_package.rb', line 32

def initialize(zipfile)
  self.zipfile = zipfile
  @bitstreams = {}
end

Instance Attribute Details

#manifestResourceDumpManifest, ChangeDumpManifest

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.

Returns:



24
25
26
# File 'lib/resync/client/zip/zip_package.rb', line 24

def manifest
  @manifest
end

#zipfile::Zip::File

Returns the ZIP file wrapped by this package.

Returns:

  • (::Zip::File)

    the ZIP file wrapped by this package



17
18
19
# File 'lib/resync/client/zip/zip_package.rb', line 17

def zipfile
  @zipfile
end

Instance Method Details

#bitstream_for(resource) ⇒ Bitstream

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.)

Returns:

  • (Bitstream)

    a bitstream wrapping the ZIP entry for the specified resource.



47
48
49
# File 'lib/resync/client/zip/zip_package.rb', line 47

def bitstream_for(resource)
  @bitstreams[resource] ||= Bitstream.new(zipfile: @zipfile, resource: resource)
end

#bitstreamsArray<Bitstream>

Gets all bitstreams declared in the package manifest.

Returns:

  • (Array<Bitstream>)

    a list of all bitstreams in the package



53
54
55
# File 'lib/resync/client/zip/zip_package.rb', line 53

def bitstreams
  manifest.resources.to_a.map { |r| bitstream_for(r) }
end