shithub: hugo

Download patch

ref: 4c596483e1d8f47ba54ff957df2c3b17fa91aebe
parent: 6a23cd65e11c503adf04eeb6db3648ce459ff53e
author: Cameron Moore <[email protected]>
date: Tue Jan 5 11:10:29 EST 2016

Update and refactor to ack Go Authors

--- a/source/lazy_file_reader.go
+++ b/source/lazy_file_reader.go
@@ -1,4 +1,5 @@
 // Copyright 2015 The Hugo Authors. All rights reserved.
+// Portions Copyright 2009 The Go Authors.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -129,15 +130,24 @@
 		return 0, nil
 	}
 
-	// following code is taken from io.Copy in 'io/io.go'
-	buf := make([]byte, 32*1024)
+	return l.copyBuffer(w, f, nil)
+}
+
+// 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 {
-		nr, er := f.Read(buf)
+		nr, er := src.Read(buf)
 		if nr > 0 {
-			nw, ew := w.Write(buf[0:nr])
+			nw, ew := dst.Write(buf[0:nr])
 			if nw > 0 {
 				l.pos += int64(nw)
-				n += int64(nw)
+				written += int64(nw)
 			}
 			if ew != nil {
 				err = ew
@@ -156,5 +166,5 @@
 			break
 		}
 	}
-	return n, err
+	return written, err
 }