Update and refactor to ack Go Authors

This commit is contained in:
Cameron Moore 2016-01-05 16:10:29 -06:00 committed by Bjørn Erik Pedersen
parent 6a23cd65e1
commit 4c596483e1

View file

@ -1,4 +1,5 @@
// Copyright 2015 The Hugo Authors. All rights reserved. // Copyright 2015 The Hugo Authors. All rights reserved.
// Portions Copyright 2009 The Go Authors.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -129,15 +130,24 @@ func (l *LazyFileReader) WriteTo(w io.Writer) (n int64, err error) {
return 0, nil return 0, nil
} }
// following code is taken from io.Copy in 'io/io.go' return l.copyBuffer(w, f, nil)
buf := make([]byte, 32*1024) }
// copyBuffer is the actual implementation of Copy and CopyBuffer.
// If buf is nil, one is allocated.
//
// Most of this function is copied from the Go stdlib 'io/io.go'.
func (l *LazyFileReader) copyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error) {
if buf == nil {
buf = make([]byte, 32*1024)
}
for { for {
nr, er := f.Read(buf) nr, er := src.Read(buf)
if nr > 0 { if nr > 0 {
nw, ew := w.Write(buf[0:nr]) nw, ew := dst.Write(buf[0:nr])
if nw > 0 { if nw > 0 {
l.pos += int64(nw) l.pos += int64(nw)
n += int64(nw) written += int64(nw)
} }
if ew != nil { if ew != nil {
err = ew err = ew
@ -156,5 +166,5 @@ func (l *LazyFileReader) WriteTo(w io.Writer) (n int64, err error) {
break break
} }
} }
return n, err return written, err
} }