Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Open existing db #76

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions db/base_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"fmt"
"io"
"os"

"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -87,6 +88,17 @@ func MakeDefaultBaseDBFromBaseDB(db BaseDB) BaseDB {
func NewReadOnlyBaseDB(path string) (BaseDB, error) {
return newBaseDB(path, &opt.Options{ReadOnly: true}, nil, nil)
}

// OpenBaseDB opens existing database. If it does not exists error is returned instead.
func OpenBaseDB(path string) (BaseDB, error) {
_, err := os.Stat(path)
if err != nil {
return nil, err
}

return NewDefaultBaseDB(path)
}

func newBaseDB(path string, o *opt.Options, wo *opt.WriteOptions, ro *opt.ReadOptions) (*baseDB, error) {
b, err := leveldb.OpenFile(path, o)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions types/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) }
// Bytes gets the byte representation of the underlying hash.
func (h Hash) Bytes() []byte { return h[:] }

// Big converts a hash to a big integer.
func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) }

// Compare two big int representations of h and h2.
func (h Hash) Compare(h2 Hash) int {
b1 := new(big.Int).SetBytes(h[:])
Expand Down
Loading