Class: Sidetree::Model::CASFileBase

Inherits:
Object
  • Object
show all
Includes:
Util::Compressor
Defined in:
lib/sidetree/model/cas_file_base.rb

Constant Summary

Constants included from Util::Compressor

Util::Compressor::ESTIMATE_DECOMPRESSION_MULTIPLIER

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Compressor

compress

Class Method Details

.decompress(data, max_size) ⇒ String

Decompress data.

Parameters:

  • data (String)

    compressed data.

  • max_size (Integer)

Returns:

  • (String)

    decompressed data.

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sidetree/model/cas_file_base.rb', line 11

def self.decompress(data, max_size)
  begin
    Sidetree::Util::Compressor.decompress(
      data,
      max_bytes:
        max_size *
          Sidetree::Util::Compressor::ESTIMATE_DECOMPRESSION_MULTIPLIER
    )
  rescue Zlib::GzipFile::Error
    raise Sidetree::Error,
          "#{self.name.split("::").last.split(/(?=[A-Z])/).join(" ")} decompression failure"
  end
end

Instance Method Details

#to_compressString

Generate compressed data via to_json to be stored in CAS.

Returns:

  • (String)

    compressed data.



35
36
37
# File 'lib/sidetree/model/cas_file_base.rb', line 35

def to_compress
  compress(to_json)
end

#to_jsonString

Build json string to be stored in CAS. Child classes must implement this method.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


28
29
30
31
# File 'lib/sidetree/model/cas_file_base.rb', line 28

def to_json
  raise NotImplementedError,
        "You must implement #{self.class}##{__method__}"
end