protofile

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: BSD-3-Clause Imports: 5 Imported by: 2

Documentation

Overview

Package protofile implements temporary files that don't appear in filesystem namespace until closed.

Unfortunately this only works on Linux with flag O_TMPFILE. In other cases a graceful degradiation is attempted, which results in the well-known dot-files (like ".gitignore").

Unlike with traditional files with {CreateNew, Write, Close}, proto files have a lifecycle {IntentNew, Write, Persist or Zap}. While a traditional file "emerges" the instant it is created with a name, "proto files" are named only after having been "persisted" (which closes them).

Streaming of file contents is currently not supported.

Index

Constants

This section is empty.

Variables

View Source
var IntentNew func(path, filename string) (ProtoFileBehaver, error) = intentNewUniversal

IntentNew "creates" a file which, ideally, is nameless at that point.

Functions

This section is empty.

Types

type ProtoFile

type ProtoFile struct {
	*os.File
	// contains filtered or unexported fields
}

ProtoFile represents a file that can be discarded or named after having been written. (With normal files such an committment is made ex ante, on creation.)

type ProtoFileBehaver

type ProtoFileBehaver interface {
	// Discards a file that has not yet been persisted/closed, else a NOP.
	Zap() error

	// Emerges the file under the initially given name into observable namespace on disk.
	// This closes the file.
	Persist() error

	io.WriteCloser
}

ProtoFileBehaver is implemented by all variants of ProtoFile.

Use this in pointers to any ProtoFile you want to utilize.

Jump to

Keyboard shortcuts

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