Skip to content

Instantly share code, notes, and snippets.

@joshuarubin
Last active July 18, 2016 18:28
Show Gist options
  • Save joshuarubin/533d74ebd138e702414755198da467da to your computer and use it in GitHub Desktop.
Save joshuarubin/533d74ebd138e702414755198da467da to your computer and use it in GitHub Desktop.
hodor6
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