On Thu, Nov 28, 2013 at 12:41 PM, Leslie Zhai <
xiang...@gmail.com> wrote:
> Hi Dave,
>
> I use net.Conn.Read(data []byte) in a for LOOP, such as
> for {
> data := make([]byte, buffer_size)
> n, err := http.conn.Read(data)
> if err != nil {
> return
> }
> f.WriteAt(data[:n], int64(http.offset))
> if http.Callback != nil {
> http.Callback(n)
> }
> http.offset += n
> }
> And I tested it using 3 connctions number (with/without) limited download
> speed, net.Conn.Read() in a for LOOP worked well :)
>
> To io.Copy(chunkFile, resp.Body), because it is using multiply connections
> for one file, it need to create several (depend on connection number) chunk
> files, when download finished, combined chunks into one output file
>
https://github.com/xiangzhai/goaxel/blob/25e604de2e0c016bf8bd759f7e7bcd8468b9cf5e/goaxel.go#L119
> If directly io.Copy(outputFile, resp.Body) without chunk files, the
> goroutines might io.Copy the output file with wrong file position indicator,
> for example, downloaded a PNG image, the output file might be disordered.