aboutsummaryrefslogtreecommitdiffhomepage
path: root/source
diff options
context:
space:
mode:
authorCameron Moore <[email protected]>2016-01-05 16:10:29 -0600
committerBjørn Erik Pedersen <[email protected]>2016-01-05 23:30:33 +0100
commit4c596483e1d8f47ba54ff957df2c3b17fa91aebe (patch)
tree54b27a06a931e71eba849f21757c07a1617ab6dd /source
parent6a23cd65e11c503adf04eeb6db3648ce459ff53e (diff)
downloadhugo-4c596483e1d8f47ba54ff957df2c3b17fa91aebe.tar.gz
hugo-4c596483e1d8f47ba54ff957df2c3b17fa91aebe.zip
Update and refactor to ack Go Authors
Diffstat (limited to 'source')
-rw-r--r--source/lazy_file_reader.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/source/lazy_file_reader.go b/source/lazy_file_reader.go
index b11644bef..6e75055ad 100644
--- 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 @@ func (l *LazyFileReader) WriteTo(w io.Writer) (n int64, err error) {
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 @@ func (l *LazyFileReader) WriteTo(w io.Writer) (n int64, err error) {
break
}
}
- return n, err
+ return written, err
}