Last active
July 18, 2016 18:28
-
-
Save joshuarubin/533d74ebd138e702414755198da467da to your computer and use it in GitHub Desktop.
hodor6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Process(w io.Writer, r io.Reader) error { | |
var buf, rbuf bytes.Buffer | |
for { | |
_, err := io.CopyN(&buf, r, DefaultChunkSize) | |
if err != nil && err != io.EOF { | |
return err | |
} | |
if rerr := Replace(buf.Bytes(), []byte("hodor"), []byte("hold the door"), -1, &rbuf); rerr != nil { | |
return rerr | |
} | |
buf.Reset() | |
if _, werr := w.Write(rbuf.Bytes()); werr != nil { | |
return werr | |
} | |
if err == io.EOF { | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment