Class: Resync::Client::Zip::Bitstream

Inherits:
Object
  • Object
show all
Defined in:
lib/resync/client/zip/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.



29
30
31
32
# File 'lib/resync/client/zip/bitstream.rb', line 29

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

Instance Attribute Details

#metadataMetadata

Returns the metadata for this bitstream.

Returns:

  • (Metadata)

    the metadata for this bitstream



20
21
22
# File 'lib/resync/client/zip/bitstream.rb', line 20

def 
  @metadata
end

#pathString

Returns the path to the entry within the ZIP file.

Returns:

  • (String)

    the path to the entry within the ZIP file



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

def path
  @path
end

#resourceResource

Returns the resource describing this bitstream.

Returns:

  • (Resource)

    the resource describing this bitstream



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

def resource
  @resource
end

Instance Method Details

#contentObject

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



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

def content
  @content ||= get_input_stream.read
end

#get_input_stream::Zip::InputStream

The bitstream, as an IO-like object. Each call to this method will return a new stream.

Returns:

  • (::Zip::InputStream)

    the bitstream.



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

def get_input_stream # rubocop:disable Style/AccessorMethodName
  @zip_entry.get_input_stream
end

#mime_typeObject

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



56
57
58
# File 'lib/resync/client/zip/bitstream.rb', line 56

def mime_type
  @mime_type ||= .mime_type
end

#sizeObject

The (uncompressed) size of the bitstream.



38
39
40
# File 'lib/resync/client/zip/bitstream.rb', line 38

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