From 12b0cdde06d5dde2a8ef38425e5062c366f387aa Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 19 May 2017 11:01:44 +0200 Subject: [PATCH] mediaapi/writers/upload: Explain the use of TeeReader --- src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go index 05db45630..a5f5894cd 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go @@ -162,6 +162,8 @@ func writeFileWithLimitAndHash(r io.Reader, cfg *config.MediaAPI, logger *log.En // integrity checks on the file data in the repository. The hash gets used as // the MediaID. hasher := sha256.New() + // A TeeReader is used to allow us to read from the limitedBody and simultaneously + // write to the hasher here and to the http.ResponseWriter via the io.Copy call below. reader := io.TeeReader(limitedBody, hasher) bytesWritten, err := io.Copy(writer, reader)