Last active
April 14, 2017 08:11
-
-
Save aki237/2cc7b7aad65885c09422b207b472c7df 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
// import this awesome package : github.com/cheggaaa/pb | |
// Create a new bar with int64 content corresponding to the total file size. | |
bar := pb.New64(head.ContentLength) | |
// Refresh rate - Nanosecond is too much... Just for fun... | |
bar.RefreshRate = time.Nanosecond | |
// Show the download speed. | |
bar.ShowSpeed = true | |
// Units : B/s (autmatically switches to MB/s kB/s etc.,) | |
bar.Units = pb.U_BYTES | |
// Start displaying the bar. | |
bar.Start() | |
// variable for storing total bytes completed downloading. | |
w := int64(0) | |
// Loop till the total is full or 100% | |
for w < head.ContentLength { | |
w += (<-written) // Get the amount written from the channel passed to various goroutines. | |
bar.Set64(w) // set the amount finished to the progressbar... | |
} | |
// Done?? Display this and stop updating. | |
bar.FinishPrint("Appending Files...") | |
// This is the WaitGroup waiting till the Job count is 0 | |
// Almost like `for jobCount == 0 {}` | |
// I know that above loop `for w < head.ContentLength ` does the same. | |
// Still to make sure. | |
c.Wait() | |
// Append all the files... | |
addParts(outfile, files) | |
// Remove the temporary directory corresponding to the download.... | |
os.RemoveAll(filepath.Join("/tmp/", outfile)) | |
// END OF MAIN.... DONE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment