FAQ
Hi Nigel,

Thanks for your advice, I reduced make byte array times :)
https://github.com/xiangzhai/goaxel/blob/master/conn/http.go#L128

I chosed outputFile.WriteAt(data[:n], int64(http.offset)) now, directly
WriteAt data with offset into output file, it does not need to make
chunk files any more.

Leslie
On Thu, Nov 28, 2013 at 12:41 PM, Leslie Zhai wrote:
for {
data := make([]byte, buffer_size)
n, err := http.conn.Read(data)
etc
}
If you insist on doing it this way, at least re-use the buffer instead
of creating garbage on every loop iteration. Do this:

data := make([]byte, bufferSize)
for {
n, err := http.conn.Read(data)
etc
}

instead of

for {
data := make([]byte, bufferSize)
n, err := http.conn.Read(data)
etc
}

but Dave Cheney is right, and you should read
http://golang.org/pkg/io/#Reader carefully.

I also think that you may be able to open the file multiple times, one
for each connection, and use a single File.Seek followed by an
io.Copy, instead of rolling your own with File.WriteAt.

Or if you insist on staging the download in chunk files, concatenating
the chunks into the destination file (your writeChunk function) can be
a series of io.Copy calls instead of rolling your own inner for loop.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 13 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 27, '13 at 10:15a
activeApr 15, '14 at 10:08a
posts13
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase