exportpkg

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exportpkg is the format of an export package: a directory (or archive) with a manifest, one JSON Lines file per collection in the API representation, the files the documents reference and the wrapped keys of encrypted fields. The server streams the parts and the CLI writes them; import reads them back.

Index

Constants

View Source
const (
	ManifestName = "manifest.json"
	DataKeysName = "_system/data_keys.jsonl"
	FilesDir     = "_files"
)

Fixed names inside a package.

View Source
const (
	FormCiphertext = "ciphertext"
	FormPlaintext  = "plaintext"
)

Form says whether an encrypted field's values travel as they are stored or decrypted.

View Source
const FormatVersion = 1

FormatVersion is the version of the package layout; import refuses other versions.

Variables

This section is empty.

Functions

func AuthPart

func AuthPart(collection string) string

AuthPart is the package path of a collection of authentication data.

func CollectionPart

func CollectionPart(database, collection string) string

CollectionPart is the package path of a collection's documents.

func DecodeDocument

func DecodeDocument(line []byte) (map[string]any, error)

DecodeDocument reads a line EncodeDocument wrote: integers come back as int64, other numbers as float64, and Extended JSON dates and binary as time.Time and []byte (an encrypted value, binary of subtype 6, as fieldcrypt.Ciphertext).

func EncodeDocument

func EncodeDocument(doc map[string]any) ([]byte, error)

EncodeDocument renders a document as one line of JSON in the API representation, with typed values in MongoDB Extended JSON (relaxed): a date is {"$date": "…"}, binary is {"$binary": {"base64": "…", "subType": "00"}}. The line has no newline.

func FilePart

func FilePart(database, fileID string) string

FilePart is the package path of a file's object.

func ReadDocuments

func ReadDocuments(r io.Reader, fn func(line int, doc map[string]any) error) error

ReadDocuments calls fn with every document of a JSON Lines stream, with its line number.

func SafePart

func SafePart(p string) bool

SafePart reports whether a package path is one this package would write: relative, with no dot segments, so a hostile archive or manifest can't name a file outside the package.

func Select

func Select(doc map[string]any, paths []string) map[string]any

Select keeps of a document its id and the given field paths ("a", "a.b", "_meta.owner"): a path naming an object keeps all of it, one that is missing in the document adds nothing. "_meta" is only present when a path asks for it.

func WriteCSV

func WriteCSV(src io.ReadSeeker, w io.Writer, fields []string) (int64, error)

WriteCSV turns a JSON Lines stream of documents into one RFC 4180 table, and returns how many rows it wrote. The columns are the union of every document's flattened paths: nested objects become "a.b" columns, `_meta` becomes "_meta.owner" and so on, arrays become JSON text in one cell, dates RFC 3339 text, binary values (ciphertext) base64 text, null and missing empty. "id" comes first; then the columns of fields in the order given (all of them, sorted, when none is), `_meta` last. It reads the stream twice (columns, then rows), so the source must seek. A text cell that a spreadsheet would run as a formula (it starts with =, +, - or @) gets a leading apostrophe.

Types

type Collection

type Collection struct {
	Name      string `json:"name"`
	Documents int64  `json:"documents"`
	Part      string `json:"part"`
}

Collection is a collection in a package: its part and how many documents it holds.

type Database

type Database struct {
	Name        string       `json:"name"`
	Collections []Collection `json:"collections"`
}

Database is a database of the realm in a package.

type EncryptedField

type EncryptedField struct {
	Database    string `json:"database"`
	Collection  string `json:"collection"`
	Path        string `json:"path"`
	Key         string `json:"key"`
	Fingerprint string `json:"fingerprint"`
	Form        string `json:"form"`
}

EncryptedField records an encrypted field and whether the package holds it as ciphertext or decrypted.

type Exclusion added in v0.9.2

type Exclusion struct {
	What   string `json:"what"`
	Reason string `json:"reason"`
}

Exclusion is something a personal data export does not take, with the reason.

type Flags

type Flags struct {
	Partial    bool `json:"partial"`
	Anonymized bool `json:"anonymized"`
	Auth       bool `json:"auth"`
	NoFiles    bool `json:"no_files"`
	// CSV marks a flat reporting extract: lossy, never importable.
	CSV bool `json:"csv"`
	// Personal marks the export of one user's personal data (always partial: it is not a copy of
	// the realm and is never importable).
	Personal bool `json:"personal,omitempty"`
}

Flags are the package's properties an import has to respect.

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

Hasher computes the SHA-256 of what passes through it.

func NewHasher

func NewHasher() *Hasher

NewHasher starts a checksum.

func WriteAtomic added in v0.9.4

func WriteAtomic(dst string, fn func(w io.Writer) error) (*Hasher, error)

WriteAtomic writes dst through fn: the bytes go to dst+".partial", which replaces dst only when fn and the close succeed, and is removed otherwise. The returned Hasher holds the checksum and size of what fn wrote.

func (*Hasher) Size

func (s *Hasher) Size() int64

Size is how many bytes passed through.

func (*Hasher) Sum

func (s *Hasher) Sum() string

Sum is the checksum as "sha256:<hex>".

func (*Hasher) Write

func (s *Hasher) Write(p []byte) (int, error)

Write implements io.Writer.

type Manifest

type Manifest struct {
	Format       int               `json:"format"`
	BackdVersion string            `json:"backd_version"`
	Realm        string            `json:"realm"`
	CreatedAt    time.Time         `json:"created_at"`
	Operator     string            `json:"operator"`
	Fingerprint  string            `json:"config_fingerprint"`
	Flags        Flags             `json:"flags"`
	Databases    []Database        `json:"databases"`
	Encrypted    []EncryptedField  `json:"encrypted_fields"`
	Checksums    map[string]string `json:"checksums"`
	Files        int64             `json:"files"`
	// Auth lists the authentication data parts (with --include auth); AuthKey is the fingerprint
	// of the one-time export key their realm-sealed fields are sealed under.
	Auth    []Collection `json:"auth,omitempty"`
	AuthKey string       `json:"auth_key_fingerprint,omitempty"`
	// Subject is the user a personal data export is about; Exclusions lists what it leaves out
	// and why. Neither is in the export of a realm.
	Subject    string      `json:"subject,omitempty"`
	Exclusions []Exclusion `json:"exclusions,omitempty"`
}

Manifest describes a package.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest reads a manifest and refuses a format this backd doesn't know.

func (*Manifest) Marshal

func (m *Manifest) Marshal() ([]byte, error)

Marshal renders the manifest, with its checksums in a stable order.

func (*Manifest) Write added in v0.9.4

func (m *Manifest) Write(dir string) error

Write stores the manifest as ManifestName in dir.

Jump to

Keyboard shortcuts

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