Class: Resync::Bitstream

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

Overview

A single entry in a ZIP package.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipfile:, resource:) ⇒ Bitstream

Creates a new bitstream for the specified resource.

Parameters:

  • zipfile (Zip::File) —

    The zipfile to read the bitstream from.

  • resource (Resource) —

    The resource describing the bitstream.



25
26
27
28
# File 'lib/resync/client/bitstream.rb', line 25

def initialize(zipfile:, resource:)
  self.resource = resource
  @zip_entry = zipfile.find_entry(@path)
end

Instance Attribute Details

#metadata ⇒ Metadata

Returns the metadata for this bitstream.

Returns:

  • (Metadata) —

    the metadata for this bitstream



16
17
18
# File 'lib/resync/client/bitstream.rb', line 16

def 
  @metadata
end

#path ⇒ String

Returns the path to the entry within the ZIP file.

Returns:

  • (String) —

    the path to the entry within the ZIP file



10
11
12
# File 'lib/resync/client/bitstream.rb', line 10

def path
  @path
end

#resource ⇒ Resource

Returns the resource describing this bitstream.

Returns:

  • (Resource) —

    the resource describing this bitstream



13
14
15
# File 'lib/resync/client/bitstream.rb', line 13

def resource
  @resource
end

Instance Method Details

#content ⇒ Object

The content of the bitstream. The content will be read only once.



46
47
48
# File 'lib/resync/client/bitstream.rb', line 46

def content
  @content ||= stream.read
end

#mime_type ⇒ Object

The content type of the bitstream, as per #metadata.



51
52
53
# File 'lib/resync/client/bitstream.rb', line 51

def mime_type
  @mime_type ||= .mime_type
end

#size ⇒ Object

The (uncompressed) size of the bitstream.



34
35
36
# File 'lib/resync/client/bitstream.rb', line 34

def size
  @size ||= @zip_entry.size
end

#stream ⇒ Object

The bitstream, as an +IO+-like object. Subsequent calls will return the same stream.



40
41
42
# File 'lib/resync/client/bitstream.rb', line 40

def stream
  @stream ||= @zip_entry.get_input_stream
end