我需要加快下载大文件的速度,为此我使用了多个连接。我正在使用一个可以访问磁盘的 goroutine,它使用一个通道从多个 goroutine 接收数据,正如我在这里被建议的那样。
file, _ := os.Create(filename)
down.destination = file
for info := range down.copyInfo {
down.destination.Seek(info.start, 0)
io.CopyN(down.destination, info.from, info.length)
}
}
问题是,在大文件上重复使用时,搜索似乎会使操作变慢。当info.length更大时,它必须寻求更少的次数,并且它似乎可以更快地完成工作。但我需要做得info.length更小。有没有办法让搜索更快?还是我应该只下载每个部分以分隔临时文件并最后将它们连接起来?