Golang io.copy twice on the request body

后端 未结 4 662
一向
一向 2021-02-03 11:33

I am building a blob storage system and i picked Go as the programming language. I create a stream to do a multipart file upload from client to the blob server.

The stre

4条回答
  •  温柔的废话
    2021-02-03 12:06

    I would suggest using an io.TeeReader if you want to push all reads from the blob through the sha1 concurrently.

    bodyReader := io.TeeReader(body, hash)
    

    Now as the bodyReader is consumed during upload, the hash is automatically updated.

提交回复
热议问题