Class: Skyfall::CarArchive
- Inherits:
-
Object
- Object
- Skyfall::CarArchive
- Defined in:
- lib/skyfall/car_archive.rb
Instance Attribute Summary collapse
-
#roots ⇒ Object
readonly
Returns the value of attribute roots.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ CarArchive
constructor
A new instance of CarArchive.
- #section_with_cid(cid) ⇒ Object
Constructor Details
#initialize(data) ⇒ CarArchive
Returns a new instance of CarArchive.
31 32 33 34 35 36 37 |
# File 'lib/skyfall/car_archive.rb', line 31 def initialize(data) @sections = [] buffer = StringIO.new(data) read_header(buffer) read_section(buffer) until buffer.eof? end |
Instance Attribute Details
#roots ⇒ Object (readonly)
Returns the value of attribute roots.
29 30 31 |
# File 'lib/skyfall/car_archive.rb', line 29 def roots @roots end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
29 30 31 |
# File 'lib/skyfall/car_archive.rb', line 29 def sections @sections end |
Class Method Details
.convert_data(object) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/skyfall/car_archive.rb', line 44 def self.convert_data(object) if object.is_a?(Hash) object.each do |k, v| if v.is_a?(Hash) || v.is_a?(Array) convert_data(v) elsif v.is_a?(CBOR::Tagged) object[k] = make_cid_link(v) elsif v.is_a?(String) && v.encoding == Encoding::ASCII_8BIT object[k] = make_bytes(v) end end elsif object.is_a?(Array) object.each_with_index do |v, i| if v.is_a?(Hash) || v.is_a?(Array) convert_data(v) elsif v.is_a?(CBOR::Tagged) object[i] = make_cid_link(v) elsif v.is_a?(String) && v.encoding == Encoding::ASCII_8BIT object[i] = make_bytes(v) end end else raise DecodeError, "Unexpected value type in record: #{object}" end end |
.make_bytes(data) ⇒ Object
74 75 76 |
# File 'lib/skyfall/car_archive.rb', line 74 def self.make_bytes(data) { '$bytes' => Base64.encode64(data).chomp.gsub(/=+$/, '') } end |
.make_cid_link(cid) ⇒ Object
70 71 72 |
# File 'lib/skyfall/car_archive.rb', line 70 def self.make_cid_link(cid) { '$link' => CID.from_cbor_tag(cid) } end |
Instance Method Details
#section_with_cid(cid) ⇒ Object
39 40 41 42 |
# File 'lib/skyfall/car_archive.rb', line 39 def section_with_cid(cid) section = @sections.detect { |s| s.cid == cid } section && section.body end |