targetfile

package
v0.0.0-...-5f25c38 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidated = errors.New("target file has been invalidated")

Functions

This section is empty.

Types

type TargetFile

type TargetFile struct {
	File        *os.File
	Filename    *string
	ShouldClose bool
	Err         error
	Fs          vfs.FS
}

func GetTargetFile

func GetTargetFile(fs vfs.FS, filename string, mode fs.FileMode, removeExisting bool) (tf *TargetFile)

GetTargetFile returns a new TargetFile instance for the given filename. If the filename is "-", the file will be os.Stdout. The file will be opened with the given mode; result.Cleanup() should be called to close the file. If removeExisting is true, the existing file will be removed before creating a new one. If the target directory does not exist, it will be created recursively with mode 0755.

func NewTargetFile

func NewTargetFile(fs vfs.FS, file *os.File, filename string, shouldClose bool) *TargetFile

NewTargetFile returns a new TargetFile instance for the given file. If the filename is "-", then:

  • result.File will be os.Stdout
  • result.shouldClose will be false.
  • result.Filename will be nil.

If the filename is empty, then:

  • result.File will be the given file
  • result.shouldClose will be false.
  • result.Filename will be nil.

func (*TargetFile) Cleanup

func (tf *TargetFile) Cleanup() error

Cleanup closes the file if it should be closed and sets the file to nil. The TargetFile instance should be considered invalid after calling this method.

func (*TargetFile) HasError

func (tf *TargetFile) HasError() bool

func (*TargetFile) HasFilename

func (tf *TargetFile) HasFilename() bool

func (*TargetFile) Invalidate

func (tf *TargetFile) Invalidate()

func (*TargetFile) IsInvalid

func (tf *TargetFile) IsInvalid() bool

func (*TargetFile) Name

func (tf *TargetFile) Name() string

func (*TargetFile) WithError

func (tf *TargetFile) WithError(err error) *TargetFile

func (*TargetFile) Write

func (tf *TargetFile) Write(data []byte, cleanup bool) error

Write writes the given data to the target file. If cleanup is true, the file will be closed after writing the data and the TargetFile instance should be considered invalid.

Jump to

Keyboard shortcuts

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