Created
April 14, 2017 07:24
-
-
Save aki237/ad57f247258f8e1e4ef6a7fc13013421 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
// Loop and make 50 go routines or cncurrent function calls.... | |
for count < 50 { | |
// Size (in no. of bytes) that has to be requested from the server | |
size := int64(bpc) | |
// If all that left is less than itself download the rest | |
// This generally happens in the last connection.... | |
if total-size < size { | |
size = total | |
} | |
// Naming the temp file for the connection.... | |
// Not necessary still little organised with numbers. | |
// Name the files with some random string and store them in the `files` array | |
num := fmt.Sprint(count + 1) | |
if count+1 < 10 { | |
num = fmt.Sprintf("0%s", num) | |
} | |
filename := filepath.Join("/tmp/", outfile, fmt.Sprintf("%s-%s", outfile, num)) | |
files = append(files, filename) | |
// Open that temp file | |
f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0755) | |
check err | |
// Add a Job to the Waitgroup | |
c.Add(1) | |
// This function will be described bottom.... | |
go Out(f, c, count, from, size, written) | |
// Calculate the size left to be downloaded. | |
total -= size | |
// Calculate from which byte size the next request has to be made. | |
from += size + 1 | |
// Increment the loop variable.... | |
count++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment