Do not read segment if no padding is necessary

Signed-off-by: Sylvain Baubeau <sbaubeau@redhat.com>
This commit is contained in:
Sylvain Baubeau 2015-06-22 21:27:49 +02:00
parent d91c4cb694
commit 5cce023aa9

View file

@ -295,7 +295,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
cursor = currentLength cursor = currentLength
paddingReader = bytes.NewReader(zeroBuf) paddingReader = bytes.NewReader(zeroBuf)
} else { } else if offset-cursor > 0 {
// Offset is inside the current segment : we need to read the // Offset is inside the current segment : we need to read the
// data from the beginning of the segment to offset // data from the beginning of the segment to offset
file, _, err := d.Conn.ObjectOpen(d.Container, getSegment(), false, nil) file, _, err := d.Conn.ObjectOpen(d.Container, getSegment(), false, nil)
@ -307,10 +307,12 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
} }
} }
multi = io.MultiReader( readers := []io.Reader{}
io.LimitReader(paddingReader, offset-cursor), if paddingReader != nil {
io.LimitReader(reader, chunkSize-(offset-cursor)), readers = append(readers, io.LimitReader(paddingReader, offset-cursor))
) }
readers = append(readers, io.LimitReader(reader, chunkSize-(offset-cursor)))
multi = io.MultiReader(readers...)
writeSegment := func(segment string) (finished bool, bytesRead int64, err error) { writeSegment := func(segment string) (finished bool, bytesRead int64, err error) {
currentSegment, err := d.Conn.ObjectCreate(d.Container, segment, false, "", d.getContentType(), nil) currentSegment, err := d.Conn.ObjectCreate(d.Container, segment, false, "", d.getContentType(), nil)