Skip to content

Commit

Permalink
simplify transform function to only pass bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
willnorris committed Dec 26, 2013
1 parent b4fae2d commit b109a87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

image, _ = transform.Transform(*image, req.Options)
b, _ := transform.Transform(image.Bytes, req.Options)
image.Bytes = b

w.Header().Add("Content-Length", strconv.Itoa(len(image.Bytes)))
w.Header().Add("Expires", image.Expires.Format(time.RFC1123))
Expand Down
9 changes: 4 additions & 5 deletions transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
var emptyOptions = new(data.Options)

// Transform the provided image.
func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
func Transform(img []byte, opt *data.Options) ([]byte, error) {
if opt == nil || reflect.DeepEqual(opt, emptyOptions) {
// bail if no transformation was requested
return &img, nil
return img, nil
}

// decode image
m, format, err := image.Decode(bytes.NewReader(img.Bytes))
m, format, err := image.Decode(bytes.NewReader(img))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -103,6 +103,5 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
break
}

img.Bytes = buf.Bytes()
return &img, nil
return buf.Bytes(), nil
}

0 comments on commit b109a87

Please sign in to comment.