Created
February 25, 2013 11:04
-
-
Save AlekSi/5029142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test case for http://code.google.com/p/go/issues/detail?id=4191 | |
package main | |
import ( | |
"bytes" | |
"io" | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
url := "https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg" // anything relatively big | |
resp, err := http.Get(url) | |
if err != nil { | |
log.Fatal(err) | |
} | |
done := make(chan bool) | |
go func() { | |
dst := &bytes.Buffer{} | |
bytes, err := io.Copy(dst, resp.Body) | |
log.Printf("Copied %d/%d bytes.", bytes, resp.ContentLength) | |
if err != nil { | |
log.Fatalf("Copy error: %s", err) | |
} | |
done <- true | |
}() | |
// abort download after one second | |
time.Sleep(time.Second) | |
log.Print("Closing...") | |
err = resp.Body.Close() | |
if err != nil { | |
log.Fatalf("Close error: %s", err) | |
} | |
log.Print("Closed.") | |
<-done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment