Class: LZ4::BasicStream::Header
- Inherits:
-
Struct
- Object
- Struct
- LZ4::BasicStream::Header
- Defined in:
- lib/extlz4/oldstream.rb,
lib/extlz4/oldstream.rb
Instance Attribute Summary collapse
-
#blockchecksum ⇒ Object
Returns the value of attribute blockchecksum.
-
#blockindependence ⇒ Object
Returns the value of attribute blockindependence.
-
#blocksize ⇒ Object
Returns the value of attribute blocksize.
-
#magic ⇒ Object
Returns the value of attribute magic.
-
#predictid ⇒ Object
Returns the value of attribute predictid.
-
#streamchecksum ⇒ Object
Returns the value of attribute streamchecksum.
-
#streamsize ⇒ Object
Returns the value of attribute streamsize.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#blockchecksum ⇒ Object
Returns the value of attribute blockchecksum
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def blockchecksum @blockchecksum end |
#blockindependence ⇒ Object
Returns the value of attribute blockindependence
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def blockindependence @blockindependence end |
#blocksize ⇒ Object
Returns the value of attribute blocksize
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def blocksize @blocksize end |
#magic ⇒ Object
Returns the value of attribute magic
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def magic @magic end |
#predictid ⇒ Object
Returns the value of attribute predictid
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def predictid @predictid end |
#streamchecksum ⇒ Object
Returns the value of attribute streamchecksum
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def streamchecksum @streamchecksum end |
#streamsize ⇒ Object
Returns the value of attribute streamsize
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def streamsize @streamsize end |
#version ⇒ Object
Returns the value of attribute version
121 122 123 |
# File 'lib/extlz4/oldstream.rb', line 121 def version @version end |
Class Method Details
.load(io) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/extlz4/oldstream.rb', line 131 def self.load(io) case magic = io.read(4).unpack("V") when MAGIC_NUMBER_LEGACY new(magic, -1, true, false, false, 8 * 1024 * 1024, nil, nil) when MAGIC_NUMBER (sf, bd) = io.read(2).unpack("CC") version = (sf >> 6) & 0x03 raise "stream header error - wrong version number" unless version == 0x01 blockindependence = ((sf >> 5) & 0x01) == 0 ? false : true blockchecksum = ((sf >> 4) & 0x01) == 0 ? false : true streamsize = ((sf >> 3) & 0x01) == 0 ? false : true streamchecksum = ((sf >> 2) & 0x01) == 0 ? false : true # reserved = (sf >> 1) & 0x01 predictid = ((sf >> 0) & 0x01) == 0 ? false : true # reserved = (bd >> 7) & 0x01 blockmax = (bd >> 4) & 0x07 # reserved = (bd >> 0) & 0x0f blocksize = BLOCK_MAXIMUM_SIZES[blockmax] raise Error, "stream header error - wrong block maximum size (#{blockmax} for 4 .. 7)" unless blocksize streamsize = io.read(8).unpack("Q<")[0] if streamsize predictid = io.read(4).unpack("V")[0] if predictid headerchecksum = io.getbyte new(magic, version, blockindependence, blockchecksum, streamchecksum, blocksize, streamsize, predictid) else raise "could not recognized magic number (0x%08x)" % (magic || nil) end end |
.pack(*args) ⇒ Object
164 165 166 |
# File 'lib/extlz4/oldstream.rb', line 164 def self.pack(*args) new(*args).pack end |
Instance Method Details
#pack ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/extlz4/oldstream.rb', line 168 def pack raise "wrong magic number" unless magic == MAGIC_NUMBER raise "wrong version number" unless version == VERSION_NUMBER header = [magic].pack("V") sd = version | (blockindependence ? BLOCK_INDEPENDENCY : 0) | (blockchecksum ? BLOCK_CHECKSUM : 0) | (streamsize ? STREAM_SIZE : 0) | (streamchecksum ? STREAM_CHECKSUM : 0) | (predictid ? PRESET_DICTIONARY : 0) bd = (BLOCK_MAXIMUM_SIZES.rassoc(blocksize)[0] << 4) desc = [sd, bd].pack("CC") header << desc header << [streamsize].pack("Q<") if streamsize header << [predictid].pack("V") if predictid header << [XXhash.xxh32(desc) >> 8].pack("C") end |