Skip to content

Instantly share code, notes, and snippets.

@farhany
Created April 24, 2019 03:58
Show Gist options
  • Save farhany/1aa95e1c342ab8722bd2adb7afbcf591 to your computer and use it in GitHub Desktop.
Save farhany/1aa95e1c342ab8722bd2adb7afbcf591 to your computer and use it in GitHub Desktop.
Basic use of TeeReader to reduce memory consumption
// Source: https://stackoverflow.com/questions/41947307/how-to-return-hash-and-bytes-in-one-step-in-go
hasher := sha256.New()
f, err := os.Open(fname)
data := io.TeeReader(f, hasher)
// Now read from data as usual, which is still a stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment