I assume you mean downloading via http (validation errors omitted for brevity):
import ("net/http"; "io"; "os") ... out, err := os.Create("output.txt") defer out.Close() ... resp, err := http.Get("http://example.com/") defer resp.Body.Close() ... n, err := io.Copy(out, resp.Body)
The body of http.Response is a reader, so you can use any functions that take a reader, for example, read a piece at a time, and not all at once. In this particular case, io.Copy() does the gruntwork for you.
Steve M Jul 27 '12 at 17:50 2012-07-27 17:50
source share