func NDBMerge(db *nutsdb.DB, dir string) error {
	var err error
	err = db.Merge()
	if err != nil {
		return err
	}
	segs, err := ioutil.ReadDir(dir)
	if err != nil {
		return err
	}
	for _, seg := range segs {
		sn := seg.Name()
		ss := seg.Size()
		fn := dir + "/" + sn
		emptyBuffer := make([]byte, ss)
		segmentBuffer, err := ioutil.ReadFile(fn)
		if err != nil {
			return err
		}
		if segmentBuffer != nil {
			if bytes.Equal(emptyBuffer, segmentBuffer) {
				err = RemoveSegment(fn)
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
NDBMerge : NutsDB merge compaction function
package main
import (
	"bytes"
	"errors"
	"github.com/eltaline/bolt"
	"github.com/eltaline/nutsdb"
	"io/ioutil"
	"os"
	"time"
)
func BoltOpenWrite(dbpath string, fmode os.FileMode, timeout time.Duration, opentries int, freelist string) (*bolt.DB, error) {
	i := 0
	flist := bolt.FreelistMapType
	switch {
	case freelist == "hashmap":
		flist = bolt.FreelistMapType
	case freelist == "array":
		flist = bolt.FreelistArrayType
	}
	for {
		i++
		db, err := bolt.Open(dbpath, fmode, &bolt.Options{Timeout: timeout, FreelistType: flist})
		if err == nil {
			return db, err
		}
		if i >= opentries {
			return db, err
		}
		time.Sleep(defsleep)
	}
}
func BoltOpenRead(dbpath string, fmode os.FileMode, timeout time.Duration, opentries int, freelist string) (*bolt.DB, error) {
	i := 0
	flist := bolt.FreelistMapType
	switch {
	case freelist == "hashmap":
		flist = bolt.FreelistMapType
	case freelist == "array":
		flist = bolt.FreelistArrayType
	}
	for {
		i++
		db, err := bolt.Open(dbpath, fmode, &bolt.Options{Timeout: timeout, ReadOnly: true, FreelistType: flist})
		if err == nil {
			return db, err
		}
		if i >= opentries {
			return db, err
		}
		time.Sleep(defsleep)
	}
}
func NDBInsert(db *nutsdb.DB, bucket string, key []byte, value []byte, ttl uint32) error {
	nerr := db.Update(func(tx *nutsdb.Tx) error {
		err := tx.Put(bucket, key, value, ttl)
		if err != nil {
			return err
		}
		return nil
	})
	if nerr != nil {
		return nerr
	}
	return nil
}
func NDBDelete(db *nutsdb.DB, bucket string, key []byte) error {
	nerr := db.Update(func(tx *nutsdb.Tx) error {
		err := tx.Delete(bucket, key)
		if err != nil {
			return err
		}
		return nil
	})
	if nerr != nil {
		return nerr
	}
	return nil
}