From 472e2d01ddfe4824216dc22ce58828994064fbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Sat, 4 May 2024 17:34:41 +0200 Subject: [PATCH] Implement DB.ImportFromFile and deprecate DB.Import --- db.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/db.go b/db.go index ca52428..980c22e 100644 --- a/db.go +++ b/db.go @@ -185,7 +185,21 @@ func NewPersistentDB(path string, compress bool) (*DB, error) { // // - filePath: Mandatory, must not be empty // - encryptionKey: Optional, must be 32 bytes long if provided +// +// Deprecated: Use [DB.ImportFromFile] instead. func (db *DB) Import(filePath string, encryptionKey string) error { + return db.ImportFromFile(filePath, encryptionKey) +} + +// ImportFromFile imports the DB from a file at the given path. The file must be +// encoded as gob and can optionally be compressed with flate (as gzip) and encrypted +// with AES-GCM. +// This works for both the in-memory and persistent DBs. +// Existing collections are overwritten. +// +// - filePath: Mandatory, must not be empty +// - encryptionKey: Optional, must be 32 bytes long if provided +func (db *DB) ImportFromFile(filePath string, encryptionKey string) error { if filePath == "" { return fmt.Errorf("file path is empty") }