mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 23:13:11 -06:00
mediaapi/writers/upload: Explain the use of TeeReader
This commit is contained in:
parent
f7d11f87c1
commit
12b0cdde06
|
|
@ -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
|
// integrity checks on the file data in the repository. The hash gets used as
|
||||||
// the MediaID.
|
// the MediaID.
|
||||||
hasher := sha256.New()
|
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)
|
reader := io.TeeReader(limitedBody, hasher)
|
||||||
|
|
||||||
bytesWritten, err := io.Copy(writer, reader)
|
bytesWritten, err := io.Copy(writer, reader)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue