Download File with Size Limit in Golang
Mar 10, 2017
It’s a common case to download a file with full size, but what if we want to download only the first few bytes of the file? For example if we want to check the file header or to check the file existence.
Should we download file to buffer and copy it to local disk by counting bytes? No, Go offers a super easy function to handle this, io.Copy().
1 | func copyMax(dst io.Writer, src io.Reader, n int64) error { |