Class: Zrip::Dictionary
- Inherits:
-
Data
- Object
- Data
- Zrip::Dictionary
- Defined in:
- lib/zrip/dictionary.rb,
lib/zrip/dictionary.rb
Constant Summary collapse
- ZDICT_MAGIC =
"\x37\xA4\x30\xEC".b.freeze
- USER_DICT_ID_MIN =
32_768- USER_DICT_ID_MAX =
(2**31) - 1
- USER_DICT_ID_SIZE =
USER_DICT_ID_MAX - USER_DICT_ID_MIN + 1
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(bytes:, id: nil) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #size ⇒ Object
Constructor Details
#initialize(bytes:, id: nil) ⇒ Dictionary
Returns a new instance of Dictionary.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zrip/dictionary.rb', line 15 def initialize(bytes:, id: nil) b = bytes.b id ||= if b.byteslice(0, 4) == ZDICT_MAGIC b.byteslice(4, 4).unpack1("V") else raw = Digest::SHA256.digest(b).byteslice(0, 4).unpack1("V") USER_DICT_ID_MIN + (raw % USER_DICT_ID_SIZE) end super(bytes: b.freeze, id: id) end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes
6 7 8 |
# File 'lib/zrip/dictionary.rb', line 6 def bytes @bytes end |
#id ⇒ Object (readonly)
Returns the value of attribute id
6 7 8 |
# File 'lib/zrip/dictionary.rb', line 6 def id @id end |
Instance Method Details
#size ⇒ Object
27 28 29 |
# File 'lib/zrip/dictionary.rb', line 27 def size bytes.bytesize end |