gzbolt

package module
v0.0.0-...-1b4fb1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 9 Imported by: 1

README

gz-boltdb

Gz compression for boltdb.

Build Status codecov GoDoc

For usage, please check out the godoc reference and the full example.

Keybase PGP Keybase XLM

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(gzFilePath string, options *bolt.Options, strict bool) (db *bolt.DB, err error)

Open behaves like bolt's Open, but works by unpacking the path gz file into a temporary file and using that as the db. The options param is used while opening the database in the temporary file. If the strict flag is set, the function will return an error instead of create a tmp database.

func Write

func Write(db *bolt.DB, file *os.File, gzHeader *gzip.Header) error

Write dumps the db to an open file. Will return err if the file is not writeable. gzHeaders can be passed. * You can create or overwrite a target file like this: f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)

if err != nil {
	return err
}

defer f.Close()

Example

Example shows

// create bolt db in a temp file and write a piece of data ("something") in a bucket
db, err := newDbWithData(&bolt.Options{Timeout: 1 * time.Second}, "something")
if err != nil {
	log.Fatalf(fmt.Errorf("problem with creating test db: %w", err).Error())
}
defer db.Close()

// create a writeable *os.File in order to feed it to Write
tmpfile, err := ioutil.TempFile("", "gz-*")
if err != nil {
	log.Fatalf(fmt.Errorf("problem with obtaining a valid writeable *os.File: %w", err).Error())
}
defer os.Remove(tmpfile.Name())

// Write gz to the previously created file.
// The gz headers can be nil.
if err := Write(db, tmpfile, &gzip.Header{Comment: "my precious bbolt dump"}); err != nil {
	log.Fatalf(fmt.Errorf("problem with writing db to: %w", err).Error())
}

// Open the freshly written archive
db, err = Open(tmpfile.Name(), nil, false)
if err != nil {
	log.Fatalf(fmt.Errorf("problem with opening the gz: %w", err).Error())
}

// check that it has "something" in it
if err = dbHasData(db, "something"); err != nil {
	log.Fatalf(fmt.Errorf("problem with opening the gz: %w", err).Error())
}

fmt.Println("since we got to this point, both Write and Open funcs worked.")
Output:

since we got to this point, both Write and Open funcs worked.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL