Last active
July 18, 2016 18:04
-
-
Save joshuarubin/18e9bb27cb78a672dd4899bc73eab3de to your computer and use it in GitHub Desktop.
hodor5
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
// DefaultChunkSize is the default amount of data read from an io.Reader | |
const DefaultChunkSize = 1024 * 16 | |
// Process starts to stream data | |
func Process(r io.Reader) (io.Reader, error) { | |
var buf, rbuf, result bytes.Buffer | |
for { | |
_, err := io.CopyN(&buf, r, DefaultChunkSize) | |
if err != nil && err != io.EOF { | |
return nil, err | |
} | |
if rerr := Replace(buf.Bytes(), []byte("hodor"), []byte("hold the door"), -1, &rbuf); rerr != nil { | |
return nil, rerr | |
} | |
buf.Reset() | |
if _, werr := result.Write(rbuf.Bytes()); werr != nil { | |
return nil, werr | |
} | |
if err == io.EOF { | |
return &result, nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment