Index: src/0dev.org/predictor/predictor.go ================================================================== --- src/0dev.org/predictor/predictor.go +++ src/0dev.org/predictor/predictor.go @@ -136,27 +136,31 @@ } // Check whether we have leftover data in the buffer if len(ctx.input) > 0 { readCount = copy(output, ctx.input) - ctx.input = ctx.input[readCount:] + + // Check whether we still have leftover data in the buffer :) + if readCount < len(ctx.input) { + copy(ctx.input[:readCount], ctx.input[readCount:]) + ctx.input = ctx.input[:readCount] + } return readCount, nil } // This is single-iteration only but it is fine according to io.Reader's contract ?! // TODO - read all bytes from a block based on the hamming weight of the flag // and just shuffle them for predictions instead of bite-sized reads ;) // Read the flags - ctx.input = ctx.input[:1] - readCount, err = wrapped.Read(ctx.input) + readCount, err = wrapped.Read(ctx.input[:1]) if readCount == 0 || err != nil { return readCount, err } - flags = ctx.input[0] ctx.input = ctx.input[:8] + flags = ctx.input[0] var i uint = 0 for ; i < 8; i++ { if flags&(1< 0 { // Guess was right