Sha256: eb715870b03195b1d975b917499b9e9256ccbafcf19a9437aa13148f9e2c5137

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

module Sidetree
  module Model
    class CASFileBase
      include Sidetree::Util::Compressor

      # Decompress +data+.
      # @param [String] data compressed data.
      # @param [Integer] max_size
      # @return [String] decompressed data.
      # @raise [Sidetree::Error]
      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

      # Build json string to be stored in CAS.
      # Child classes must implement this method.
      # @return [String]
      def to_json
        raise NotImplementedError,
              "You must implement #{self.class}##{__method__}"
      end

      # Generate compressed data via to_json to be stored in CAS.
      # @return [String] compressed data.
      def to_compress
        compress(to_json)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sidetree-0.1.5 lib/sidetree/model/cas_file_base.rb
sidetree-0.1.4 lib/sidetree/model/cas_file_base.rb
sidetree-0.1.3 lib/sidetree/model/cas_file_base.rb