Class: Lz4rip::Dictionary

Inherits:
Data
  • Object
show all
Defined in:
lib/lz4rip/dictionary.rb

Overview

Immutable LZ4 dictionary value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V")) ⇒ Dictionary

Returns a new instance of Dictionary.

Parameters:

  • bytes (String)

    dictionary bytes

  • id (Integer) (defaults to: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))

    optional dictionary ID



16
17
18
# File 'lib/lz4rip/dictionary.rb', line 16

def initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))
  super(bytes: bytes.b.freeze, id: id)
end

Instance Attribute Details

#bytesString (readonly)

Returns frozen binary dictionary bytes.

Returns:

  • (String)

    frozen binary dictionary bytes



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lz4rip/dictionary.rb', line 13

Dictionary = Data.define(:bytes, :id) do
  # @param bytes [String] dictionary bytes
  # @param id [Integer] optional dictionary ID
  def initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))
    super(bytes: bytes.b.freeze, id: id)
  end


  # @return [Integer] dictionary size in bytes
  def size
    bytes.bytesize
  end
end

#idInteger (readonly)

Returns dictionary ID.

Returns:

  • (Integer)

    dictionary ID



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lz4rip/dictionary.rb', line 13

Dictionary = Data.define(:bytes, :id) do
  # @param bytes [String] dictionary bytes
  # @param id [Integer] optional dictionary ID
  def initialize(bytes:, id: Digest::SHA256.digest(bytes).byteslice(0, 4).unpack1("V"))
    super(bytes: bytes.b.freeze, id: id)
  end


  # @return [Integer] dictionary size in bytes
  def size
    bytes.bytesize
  end
end

Instance Method Details

#sizeInteger

Returns dictionary size in bytes.

Returns:

  • (Integer)

    dictionary size in bytes



22
23
24
# File 'lib/lz4rip/dictionary.rb', line 22

def size
  bytes.bytesize
end