Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Though negligible, have geezyReader satisfy ReaderFrom

  • Loading branch information...
commit 01347206dadc4df8642ca2a0079705d3d3429592 1 parent 26f9da9
@dustin dustin authored
Showing with 40 additions and 0 deletions.
  1. +4 −0 ioutil.go
  2. +36 −0 ioutil_test.go
View
4 ioutil.go
@@ -125,6 +125,10 @@ func (g *geezyWriter) Write(data []byte) (int, error) {
return g.w.Write(data)
}
+func (g *geezyWriter) ReadFrom(r io.Reader) (int64, error) {
+ return io.Copy(g.w, r)
+}
+
func (g *geezyWriter) WriteHeader(status int) {
g.orig.WriteHeader(status)
}
View
36 ioutil_test.go
@@ -2,9 +2,11 @@ package main
import (
"bytes"
+ "compress/gzip"
"io"
"io/ioutil"
"math/rand"
+ "net/http"
"reflect"
"testing"
"testing/iotest"
@@ -89,3 +91,37 @@ func BenchmarkRandomDataMaker(b *testing.B) {
}
}
}
+
+type testWriter struct {
+}
+
+func (c *testWriter) Header() http.Header {
+ return http.Header{}
+}
+
+func (c *testWriter) Write(b []byte) (int, error) {
+ return ioutil.Discard.Write(b)
+}
+
+func (c *testWriter) ReadFrom(r io.Reader) (int64, error) {
+ return io.Copy(ioutil.Discard, r)
+}
+
+func (c *testWriter) WriteHeader(code int) {
+}
+
+func BenchmarkGeezy(b *testing.B) {
+ b.StopTimer()
+ someBytes := make([]byte, 1024*1024*64)
+ b.SetBytes(int64(len(someBytes)))
+
+ w := http.ResponseWriter(&testWriter{})
+ gz := gzip.NewWriter(w)
+ defer gz.Close()
+ w = &geezyWriter{w, gz}
+
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ io.Copy(w, bytes.NewReader(someBytes))
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.