src/server/pkg/storage/chunk/reader.go
func (r *Reader) Read(data []byte) (int, error) {
	var totalRead int
	for len(data) > 0 {
		n, err := r.r.Read(data)
		data = data[n:]
		totalRead += n
		if err != nil {
			// If all DataRefs have been read, then io.EOF.
			if len(r.dataRefs) == 0 {
				return totalRead, io.EOF
			}
			// Get next chunk if necessary.
			if r.curr == nil || r.curr.Chunk.Hash != r.dataRefs[0].Chunk.Hash {
				if err := r.readChunk(r.dataRefs[0].Chunk); err != nil {
					return totalRead, err
				}
			}
			r.curr = r.dataRefs[0]
			r.dataRefs = r.dataRefs[1:]
			r.r = bytes.NewReader(r.buf.Bytes()[r.curr.OffsetBytes : r.curr.OffsetBytes+r.curr.SizeBytes])
		}
	}
	return totalRead, nil

}
func (r *Reader) Read(data []byte) (int, error) {
	var totalRead int
	for len(data) > 0 {
		n, err := r.r.Read(data)
		data = data[n:]
		totalRead += n
		if err != nil {
			// If all DataRefs have been read, then io.EOF.
			if len(r.dataRefs) == 0 {
				return totalRead, io.EOF
			}
			// Get next chunk if necessary.
			if r.curr == nil || r.curr.Chunk.Hash != r.dataRefs[0].Chunk.Hash {
				if err := r.readChunk(r.dataRefs[0].Chunk); err != nil {
					return totalRead, err
				}
			}
			r.curr = r.dataRefs[0]
			r.dataRefs = r.dataRefs[1:]
			r.r = bytes.NewReader(r.buf.Bytes()[r.curr.OffsetBytes : r.curr.OffsetBytes+r.curr.SizeBytes])
		}
	}
	return totalRead, nil

}
func ( r * Reader ) Read ( data [ ] byte ) ( int , error ) { var totalRead int for len ( data ) > 0 { n , err := r . r . Read ( data ) data = data [ n : ] totalRead += n if err != nil { // If all DataRefs have been read, then io.EOF. if len ( r . dataRefs ) == 0 { return totalRead , io . EOF } // Get next chunk if necessary. if r . curr == nil || r . curr . Chunk . Hash != r . dataRefs [ 0 ] . Chunk . Hash { if err := r . readChunk ( r . dataRefs [ 0 ] . Chunk ) ; err != nil { return totalRead , err } } r . curr = r . dataRefs [ 0 ] r . dataRefs = r . dataRefs [ 1 : ] r . r = bytes . NewReader ( r . buf . Bytes ( ) [ r . curr . OffsetBytes : r . curr . OffsetBytes + r . curr . SizeBytes ] ) } } return totalRead , nil }
// Read reads from the byte stream produced by the set of DataRefs.
Read reads from the byte stream produced by the set of DataRefs .