Created
February 17, 2015 14:19
-
-
Save progrium/d782e574bb2e97d5ebdc to your computer and use it in GitHub Desktop.
Comparing natural brevity and concise expressiveness between Go and shell/Bash for certain tasks using each tool's "standard" library.
This file contains hidden or 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
curl -s "$url" | tar -zxC "$dest" |
This file contains hidden or 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
func downloadAndInstall(url, dest string) error { | |
resp, err := http.Get(url) | |
if err != nil { | |
return error | |
} | |
defer resp.Body.Close() | |
zip, err := gzip.NewReader(resp.Body) | |
if err != nil { | |
return error | |
} | |
defer zip.Close() | |
archive := tar.NewReader(zip) | |
for { | |
header, err := archive.Next() | |
if err == io.EOF { | |
break | |
} | |
if err != nil { | |
return err | |
} | |
filename := fmt.Sprintf("%s/%s", dest, header.Name) | |
file, err := os.Create(filename) | |
if err != nil { | |
return err | |
} | |
defer file.Close() | |
_, err := io.Copy(file, archive) | |
if err != nil { | |
return err | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@msabramo Python's concurrency story is woeful though, and I fear that asyncio is a long winded wrong turn.