lib/sidetree/model/provisional_index_file.rb in sidetree-0.1.2 vs lib/sidetree/model/provisional_index_file.rb in sidetree-0.1.3
- old
+ new
@@ -1,9 +1,9 @@
module Sidetree
module Model
# https://identity.foundation/sidetree/spec/#provisional-index-file
- class ProvisionalIndexFile
+ class ProvisionalIndexFile < CASFileBase
attr_reader :provisional_proof_file_uri
attr_reader :chunks
attr_reader :operations
# Initialize
@@ -42,19 +42,14 @@
# @return [Sidetree::Model::ProvisionalIndexFile]
def self.parse(index_data, compressed: true)
decompressed =
(
if compressed
- begin
- Sidetree::Util::Compressor.decompress(
- index_data,
- max_bytes: Sidetree::Params::MAX_PROVISIONAL_INDEX_FILE_SIZE
- )
- rescue Zlib::GzipFile::Error
- raise Sidetree::Error,
- "Provisional Index File decompression failure"
- end
+ decompress(
+ index_data,
+ Sidetree::Params::MAX_PROVISIONAL_INDEX_FILE_SIZE
+ )
else
index_data
end
)
begin
@@ -109,13 +104,13 @@
rescue JSON::ParserError
raise Sidetree::Error, "Provisional index file is not json"
end
end
- # Compress this provisional index file
- # @return [String] compressed data.
- def to_compress
+ # Build json string to be stored in CAS.
+ # @return [String] json string.
+ def to_json
params = { chunks: chunks.map(&:to_h) }
unless operations.empty?
params[:operations] = {
update:
operations.map do |update|
@@ -125,10 +120,10 @@
}
end
}
params[:provisionalProofFileUri] = provisional_proof_file_uri
end
- Sidetree::Util::Compressor.compress(params.to_json)
+ params.to_json
end
end
end
end