Index: src/0dev.org/predictor/predictor.go ================================================================== --- src/0dev.org/predictor/predictor.go +++ src/0dev.org/predictor/predictor.go @@ -171,18 +171,20 @@ var r int r, err = reader.Read(ctx.input[predicted+rc:]) rc += r goto retryData } // Continue on any error, try to decompress and return it along the result + + // rc now contains the amount of actual bytes in this cycle (usually 8) + rc += predicted // Walk the buffer, filling in the predicted blanks, // relocating read bytes and and updating the guess table - for i, a := uint(0), predicted; i < 8; i++ { - if (flags & (1 << i)) > 0 { + for i, a := 0, predicted; i < rc; i++ { + if (flags & (1 << uint(i))) > 0 { // Guess succeeded, fill in from the table ctx.input[i] = ctx.table[ctx.hash] - rc++ } else { // Relocate a read byte ctx.input[i], a = ctx.input[a], a+1 // Guess failed, update the table ctx.table[ctx.hash] = ctx.input[i] @@ -189,11 +191,11 @@ } // Update the hash ctx.hash = (ctx.hash << 4) ^ uint16(ctx.input[i]) } - // rc now contains the precise amount of populated data + // Copy the decompressed data to the output ctx.input = ctx.input[:rc] available = copy(output, ctx.input) total += available