Skip to content

Instantly share code, notes, and snippets.

@aki237
Last active April 14, 2017 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aki237/6b212a8e7b5a83b652aa7e720db2179a to your computer and use it in GitHub Desktop.
Save aki237/6b212a8e7b5a83b652aa7e720db2179a to your computer and use it in GitHub Desktop.
total := head.ContentLength
// Say I want to make 50 connections.
// bpc is bytes per connection
bpc := total / 50
// Get the filename....
outfile := path.Base(url)
// Create a directory for our temp sections.
err = os.Mkdir(filepath.Join("/tmp/", outfile), 0755)
// `check err` means the usual check err block,
// you know with `if err != nil {...}`
check err
// This is for storing "from which byte index should be asked for from the server" for
// a new connection.
from := int64(0)
// loop variable tracking the no. of connections. (loop???... wait for it)
count := 0
// We are going to run the 50 connections concurrently.
// So we have to wait for the connections to end. Else corrupted downloads.
// When we make a new connection, we'll add 1 Job to c.(c.Add(1))
// When the connection is done, c.Done() will be called.
c := &sync.WaitGroup{}
// This is a optional variable to get how much has been written
// every go routine will be sending the amount they write at any write cycle
// through this channel... I made a progress bar.
written := make(chan int64)
// To store all the tmp filenames in an array.
files := make([]string, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment