Method: LZ4::StreamDecoder#initialize
- Defined in:
- lib/extlz4/oldstream.rb
#initialize(io) ⇒ StreamDecoder
Returns a new instance of StreamDecoder.
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/extlz4/oldstream.rb', line 359 def initialize(io) magic = io.read(4).unpack("V")[0] case magic when MAGIC_NUMBER sf = io.getbyte @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 presetdict = ((sf >> 0) & 0x01) == 0 ? false : true bd = io.getbyte # reserved = (bd >> 7) & 0x01 blockmax = (bd >> 4) & 0x07 # reserved = (bd >> 0) & 0x0f @blockmaximum = BLOCK_MAXIMUM_SIZES[blockmax] raise Error, "stream header error - wrong block maximum size (#{blockmax} for 4 .. 7)" unless @blockmaximum @streamsize = io.read(8).unpack("Q<")[0] if streamsize @presetdict = io.read(4).unpack("V")[0] if presetdict headerchecksum = io.getbyte if @blockindependence @decoder = LZ4.method(:block_decode) else @decoder = LZ4::BlockDecoder.new.method(:update) end when MAGIC_NUMBER_LEGACY @version = -1 @blockindependence = true @blockchecksum = false @streamchecksum = false @blockmaximum = 1 << 23 # 8 MiB @streamsize = nil @presetdict = nil @decoder = LZ4.method(:block_decode) else raise Error, "stream header error - wrong magic number" end @io = io @pos = 0 @readbuf = "".b @decodebuf = "".b end |