// Save stores the block on disk. It returns the oldest
// block that should be pruned, if any.
Save stores the block on disk. It returns the oldest
block that should be pruned, if any.
// Save stores the block on disk . It returns the oldest // block that should be pruned if any .
func (b *Blocks) Save(block *Block) (*Block, error) {
	b.Lock()
	if len(b.buffer) > 0 {
		b.latest = (b.latest + 1) % uint32(b.limit)
		if b.oldest == b.latest {
			b.oldest = (b.oldest + 1) % uint32(b.limit)
		}
	}
	var oldBlock *Block
	if uint8(len(b.buffer)) < b.limit {
		b.buffer = append(b.buffer, block)
	} else {
		oldBlock = b.buffer[b.latest]
		b.buffer[b.latest] = block
	}
	err := StoreBlock(b.store, *block, b.latest, b.oldest, uint8(len(b.buffer)))
	b.Unlock()
	return oldBlock, err
}
func ( b * Blocks ) Save ( block * Block ) ( * Block , error ) { b . Lock ( ) if len ( b . buffer ) > 0 { b . latest = ( b . latest + 1 ) % uint32 ( b . limit ) if b . oldest == b . latest { b . oldest = ( b . oldest + 1 ) % uint32 ( b . limit ) } } var oldBlock * Block if uint8 ( len ( b . buffer ) ) < b . limit { b . buffer = append ( b . buffer , block ) } else { oldBlock = b . buffer [ b . latest ] b . buffer [ b . latest ] = block } err := StoreBlock ( b . store , * block , b . latest , b . oldest , uint8 ( len ( b . buffer ) ) ) b . Unlock ( ) return oldBlock , err }
Save stores the block on disk.
Save stores the block on disk .