github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/util/datastore2/datastore_closer.go (about)

     1  package datastore2
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
     7  )
     8  
     9  type ThreadSafeDatastoreCloser interface {
    10  	datastore.ThreadSafeDatastore
    11  	io.Closer
    12  
    13  	Batch() (datastore.Batch, error)
    14  }
    15  
    16  func CloserWrap(ds datastore.ThreadSafeDatastore) ThreadSafeDatastoreCloser {
    17  	return &datastoreCloserWrapper{ds}
    18  }
    19  
    20  type datastoreCloserWrapper struct {
    21  	datastore.ThreadSafeDatastore
    22  }
    23  
    24  func (w *datastoreCloserWrapper) Close() error {
    25  	return nil // no-op
    26  }
    27  
    28  func (w *datastoreCloserWrapper) Batch() (datastore.Batch, error) {
    29  	bds, ok := w.ThreadSafeDatastore.(datastore.BatchingDatastore)
    30  	if !ok {
    31  		return nil, datastore.ErrBatchUnsupported
    32  	}
    33  
    34  	return bds.Batch()
    35  }