files

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package files contains file-related utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

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

Writer writes a sequence of bytes to a file. In case of errors, the old file contents remain untouched since the writes are applied atomically when the Writer is closed.

func NewWriter

func NewWriter(file string) *Writer

NewWriter returns a writer that writes to the named files.

The caller should eventually call Cleanup. A recommended pattern is:

w := files.NewWriter(dst)
defer w.Cleanup()
... write to w ...
err := w.Close()

func (*Writer) Cleanup

func (w *Writer) Cleanup()

Cleanup releases any resources in use by the writer, without attempting to write collected bytes to the destination. It is safe to call Cleanup() even if Close or Cleanup have already been called.

func (*Writer) Close

func (w *Writer) Close() error

Close saves the written bytes to the destination file and closes the writer. Close returns an error if any errors were encountered, including during earlier Write calls.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes p and returns the number of bytes written, which will either be len(p), or the returned error will be non-nil.

Jump to

Keyboard shortcuts

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