Index: src/0dev.org/ioutil/ioutil.go ================================================================== --- src/0dev.org/ioutil/ioutil.go +++ src/0dev.org/ioutil/ioutil.go @@ -29,40 +29,43 @@ return ReaderFunc(func(output []byte) (readCount int, e error) { var ( bufferLength int = len(buffer) err error ) - start: // Reply with the buffered data if there is any if bufferLength > 0 { readCount = copy(output, buffer) if readCount < bufferLength { // Advance the data in the buffer - buffer = buffer[:copy(buffer, buffer[:readCount])] + buffer = buffer[:copy(buffer, buffer[readCount:])] } else { // Clear the buffer buffer = buffer[:0] } - // Stage any error for returning e, err = err, nil - return readCount, e } // Delegate if the buffer is empty and the destination buffer is large enough if len(output) >= size { - return reader.Read(output) + return reader.Read(output[:len(output)/size]) } // Extend the buffer up to the desired size and perform a Read buffer = buffer[:size] readCount, err = reader.Read(buffer) // Size the buffer down to the read data size and restart buffer = buffer[:readCount] bufferLength = len(buffer) - goto start + + if bufferLength > 0 { + goto start + } + // Stage any error for returning + e, err = err, nil + return 0, e }) } Index: src/0dev.org/predictor/predictor_test.go ================================================================== --- src/0dev.org/predictor/predictor_test.go +++ src/0dev.org/predictor/predictor_test.go @@ -138,11 +138,11 @@ delta := diff.Diff(diff.D{len(input), len(decompressed), func(i, j int) bool { return input[i] == decompressed[j] }}) // Return a well-formated error if any differences are found if len(delta.Added) > 0 || len(delta.Removed) > 0 { - return fmt.Errorf("Unexpected decompressed output %v\ninput: (%d) %#x\ntrace: (%d) %#x\noutput: (%d) %#x\n", + return fmt.Errorf("Unexpected decompressed output %v\ninput: (%d) %#x\ntrace: (%d) %#x\noutput: (%d) %#x\n", delta, len(input), input, len(trace), trace, len(decompressed), decompressed) } // All is good :) return nil