> so how can I do this check and outputting better? Because > there are many > bytes with many different meanings and as said sometimes I > need to read > in 4 bytes then just one then again 2 bytes... is this at all > possible > to do dry-like? Without knowing the details of the file you're trying to parse it's hard to say, but you might be well-served to write a simple finite state machine. E.g. something like: mode = :expect_header while !(mode == :done || mode == :fail) case mode when :expect_header if target.read(3) == $startflag mode = :expect_debug else mode = :fail end when :expect_debug case target.read(1) when "\x1" debug = true mode = :expect_body when "\x255" debug = nil mode = :expect_body else mode = :fail end end end - donald