func (f *chunkFeeder) Write(b []byte) (int, error) {
	l := len(b) // data length
	w := 0      // written

	if l+f.bufferIdx < f.size {
		// write the data into the buffer and return
		n := copy(f.buffer[f.bufferIdx:], b)
		f.bufferIdx += n
		return n, nil
	}

	// if we are here it means we have to do at least one write
	d := make([]byte, f.size+span)
	sp := 0 // span of current write

	//copy from existing buffer to this one
	sp = copy(d[span:], f.buffer[:f.bufferIdx])

	// don't account what was already in the buffer when returning
	// number of written bytes
	if sp > 0 {
		w -= sp
	}

	var n int
	for i := 0; i < len(b); {
		// if we can't fill a whole write, buffer the rest and return
		if sp+len(b[i:]) < f.size {
			n = copy(f.buffer, b[i:])
			f.bufferIdx = n
			return w + n, nil
		}

		// fill stuff up from the incoming write
		n = copy(d[span+f.bufferIdx:], b[i:])
		i += n
		sp += n

		binary.LittleEndian.PutUint64(d[:span], uint64(sp))
		args := &pipeline.PipeWriteArgs{Data: d[:span+sp], Span: d[:span]}
		err := f.next.ChainWrite(args)
		if err != nil {
			return 0, err
		}
		f.bufferIdx = 0
		w += sp
		sp = 0
	}
	f.wrote += int64(w)
	return w, nil
}
// Write writes data to the chunk feeder. It returns the number of bytes written
// to the feeder. The number of bytes written does not necessarily reflect how many
// bytes were actually flushed to subsequent writers, since the feeder is buffered
// and works in chunk-size quantiles.
Write writes data to the chunk feeder. It returns the number of bytes written
to the feeder. The number of bytes written does not necessarily reflect how many
bytes were actually flushed to subsequent writers, since the feeder is buffered
and works in chunk-size quantiles.
// Write writes data to the chunk feeder . It returns the number of bytes written // to the feeder . The number of bytes written does not necessarily reflect how many // bytes were actually flushed to subsequent writers since the feeder is buffered // and works in chunk - size quantiles .
func (f *chunkFeeder) Write(b []byte) (int, error) {
	l := len(b) 
	w := 0      
	if l+f.bufferIdx < f.size {
		n := copy(f.buffer[f.bufferIdx:], b)
		f.bufferIdx += n
		return n, nil
	}
	d := make([]byte, f.size+span)
	sp := 0 
	sp = copy(d[span:], f.buffer[:f.bufferIdx])
	if sp > 0 {
		w -= sp
	}
	var n int
	for i := 0; i < len(b); {
		if sp+len(b[i:]) < f.size {
			n = copy(f.buffer, b[i:])
			f.bufferIdx = n
			return w + n, nil
		}
		n = copy(d[span+f.bufferIdx:], b[i:])
		i += n
		sp += n
		binary.LittleEndian.PutUint64(d[:span], uint64(sp))
		args := &pipeline.PipeWriteArgs{Data: d[:span+sp], Span: d[:span]}
		err := f.next.ChainWrite(args)
		if err != nil {
			return 0, err
		}
		f.bufferIdx = 0
		w += sp
		sp = 0
	}
	f.wrote += int64(w)
	return w, nil
}
func ( f * chunkFeeder ) Write ( b [ ] byte ) ( int , error ) { l := len ( b ) w := 0 if l + f . bufferIdx < f . size { n := copy ( f . buffer [ f . bufferIdx : ] , b ) f . bufferIdx += n return n , nil } d := make ( [ ] byte , f . size + span ) sp := 0 sp = copy ( d [ span : ] , f . buffer [ : f . bufferIdx ] ) if sp > 0 { w -= sp } var n int for i := 0 ; i < len ( b ) ; { if sp + len ( b [ i : ] ) < f . size { n = copy ( f . buffer , b [ i : ] ) f . bufferIdx = n return w + n , nil } n = copy ( d [ span + f . bufferIdx : ] , b [ i : ] ) i += n sp += n binary . LittleEndian . PutUint64 ( d [ : span ] , uint64 ( sp ) ) args := & pipeline . PipeWriteArgs { Data : d [ : span + sp ] , Span : d [ : span ] } err := f . next . ChainWrite ( args ) if err != nil { return 0 , err } f . bufferIdx = 0 w += sp sp = 0 } f . wrote += int64 ( w ) return w , nil }
Write writes data to the chunk feeder.
Write writes data to the chunk feeder .
// data length // written // write the data into the buffer and return // if we are here it means we have to do at least one write // span of current write //copy from existing buffer to this one // don't account what was already in the buffer when returning // number of written bytes // if we can't fill a whole write, buffer the rest and return // fill stuff up from the incoming write