Index: src/0dev.org/predictor/predictor.go ================================================================== --- src/0dev.org/predictor/predictor.go +++ src/0dev.org/predictor/predictor.go @@ -123,13 +123,13 @@ var ctx context ctx.input = make([]byte, 0, 8) return decompressor(func(output []byte) (int, error) { var ( - err error - flags byte - rc, available, predicted int + err error + flags byte + rc, available, predicted, total int ) // Sanity check for space to read into if len(output) == 0 { return 0, nil @@ -145,16 +145,17 @@ } return rc, nil } // Read the next prediction header + readHeader: rc, err = reader.Read(ctx.input[:1]) // Fail on error unless it is EOF if err != nil && err != io.EOF { - return 0, err + return total, err } else if rc == 0 { - return 0, err + return total, err } // Extend the buffer, copy the prediction header // and calculate the number of subsequent bytes to read ctx.input = ctx.input[:8] @@ -191,17 +192,24 @@ } // rc now contains the precise amount of populated data ctx.input = ctx.input[:rc] available = copy(output, ctx.input) + + total += available // Check for remaining bytes that dont fit in the output buffer if available < rc { ctx.input = ctx.input[:copy(ctx.input, ctx.input[available:])] } else { // Clear the buffer ctx.input = ctx.input[:0] + + output = output[available:] + if len(output) > 0 && err == nil { + goto readHeader + } } - return available, err + return total, err }) }