Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.