func (b *CalibrationReadStreamer) WriteCalibrations(p []apimodel.CalibrationRead) (s *CalibrationReadStreamer, err error) {
	s = newCalibrationStreamerDuration(b.head, b.startTime, b.wr, b.d)
	if err != nil {
		return s, err
	}
	for i := range p {
		c := p[i]
		t := c.GetTime()
		truncatedTime := t.Truncate(s.d)
		if s.head == nil {
			s = newCalibrationStreamerDuration(container.NewImmutableList(nil, c), &truncatedTime, s.wr, s.d)
		} else if t.Sub(*s.startTime) >= s.d {
			s, err = s.Flush()
			if err != nil {
				return s, err
			}
			s = newCalibrationStreamerDuration(container.NewImmutableList(nil, c), &truncatedTime, s.wr, s.d)
		} else {
			s = newCalibrationStreamerDuration(container.NewImmutableList(s.head, c), s.startTime, s.wr, s.d)
		}
	}
	return s, err
}
WriteCalibrations writes the contents of p into the buffer.
It returns the number of bytes written.
If nn < len(p), it also returns an error explaining
why the write is short. p must be sorted by time (oldest to most recent).
package streaming
import (
	"github.com/alexandre-normand/glukit/app/apimodel"
	"github.com/alexandre-normand/glukit/app/container"
	"github.com/alexandre-normand/glukit/app/glukitio"
	"time"
)
type CalibrationReadStreamer struct {
	head      *container.ImmutableList
	startTime *time.Time
	wr        glukitio.CalibrationBatchWriter
	d         time.Duration
}
func NewCalibrationReadStreamerDuration(wr glukitio.CalibrationBatchWriter, bufferDuration time.Duration) *CalibrationReadStreamer {
	return newCalibrationStreamerDuration(nil, nil, wr, bufferDuration)
}
func newCalibrationStreamerDuration(head *container.ImmutableList, startTime *time.Time, wr glukitio.CalibrationBatchWriter, bufferDuration time.Duration) *CalibrationReadStreamer {
	w := new(CalibrationReadStreamer)
	w.head = head
	w.startTime = startTime
	w.wr = wr
	w.d = bufferDuration
	return w
}
func (b *CalibrationReadStreamer) WriteCalibration(c apimodel.CalibrationRead) (s *CalibrationReadStreamer, err error) {
	return b.WriteCalibrations([]apimodel.CalibrationRead{c})
}