fix offset of DownloadBufferWriter

parent 71456852
......@@ -635,13 +635,15 @@ func (r *Renter) threadedDownloadLoop() {
// DownloadBufferWriter is a buffer-backed implementation of DownloadWriter.
type DownloadBufferWriter struct {
data []byte
data []byte
offset int64
}
// NewDownloadBufferWriter creates a new DownloadWriter that writes to a buffer.
func NewDownloadBufferWriter(size uint64) *DownloadBufferWriter {
func NewDownloadBufferWriter(size uint64, offset int64) *DownloadBufferWriter {
return &DownloadBufferWriter{
data: make([]byte, size),
data: make([]byte, size),
offset: offset,
}
}
......@@ -654,7 +656,8 @@ func (dw *DownloadBufferWriter) Destination() string {
// WriteAt writes the passed bytes to the DownloadBuffer.
func (dw *DownloadBufferWriter) WriteAt(bytes []byte, off int64) (int, error) {
if len(bytes)+int(off) > len(dw.data) {
off -= dw.offset
if len(bytes)+int(off) > len(dw.data) || off < 0 {
return 0, errors.New("write at specified offset exceeds buffer size")
}
......
......@@ -331,7 +331,7 @@ func (r *Renter) managedDownloadChunkData(rs *repairState, file *file, offset ui
}
// create a DownloadBufferWriter for the chunk
buf := NewDownloadBufferWriter(file.chunkSize())
buf := NewDownloadBufferWriter(file.chunkSize(), int64(offset))
// create the download object and push it on to the download queue
d := r.newSectionDownload(file, buf, currentContracts, offset, downloadSize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment