Documentation
¶
Overview ¶
Package tempfile stages output in the destination directory and publishes it with an atomic rename. Failed or canceled work removes the staged file, leaving the final path untouched.
The creator owns cleanup. Defer the returned value's Discard method immediately after New or NewExternal; Discard is a no-op after Commit succeeds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type External ¶
type External struct {
// contains filtered or unexported fields
}
External stages output written by another process, such as ffmpeg. It reserves a temp path in the destination directory, then renames that path into place on Commit. Unlike File, External does not keep the file open for writing.
Reserve a name with NewExternal, pass Path to the process, then call Commit to publish or Discard to remove the temp.
func NewExternal ¶
NewExternal reserves a temp path next to finalPath for an external writer.
The temp name preserves finalPath's extension (for example, out.flac.*.flac), because tools like ffmpeg infer the output container from the filename extension.
func (*External) Commit ¶
Commit atomically renames the temp path to the final path. After a successful Commit, Discard is a no-op.
func (*External) Discard ¶
Discard removes the temp path. It is safe to call multiple times and is a no-op after a successful Commit.
type File ¶
File is a staged output: write to it, then Commit (atomic rename to the final path) or Discard (remove the temp). The temp is created in the final path's directory so the rename stays on one filesystem and is therefore atomic.
func New ¶
New creates a staging file for eventual atomic rename to finalPath. The returned *File embeds *os.File, so callers write to it directly.
func (*File) Commit ¶
Commit flushes and closes the temp, then atomically renames it to the final path. After a successful Commit, Discard is a no-op.