fileutils

package
v0.0.0-...-9febfc8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package fileutils defines generic file utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(ctx context.Context, srcFilePath string, dstPath string) error

CopyFile copies the file or directory at srcFilePath to dstPath. If dstPath is a directory, the file is placed within it.

func MarshalPrettyJSON

func MarshalPrettyJSON(m proto.Message) ([]byte, error)

MarshalPrettyJSON marshals the proto message into pretty, human-readable JSON.

func PathExists

func PathExists(path string) (bool, error)

PathExists returns whether the path exists. Returns a non-nil error if unable to determine if the path exists.

func ReadFile

func ReadFile(ctx context.Context, filePath string) ([]byte, error)

ReadFile reads a file's entire contents.

func WriteBytesToFile

func WriteBytesToFile(ctx context.Context, input []byte, outFilePath string) error

WriteBytesToFile writes input bytes to file. Directories in path are created if they do not exist. Existing file contents are overwritten.

Types

type ContextualReaderWrapper

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

ContextualReaderWrapper is a wrapper around an existing io.Reader that allows for the interruption of reads with the cancellation of a context.

func NewContextualReaderWrapper

func NewContextualReaderWrapper(ctx context.Context, reader io.Reader) *ContextualReaderWrapper

NewContextualReaderWrapper initializes a new ContextualReaderWrapper.

func (*ContextualReaderWrapper) Read

func (c *ContextualReaderWrapper) Read(p []byte) (n int, err error)

Read calls io.Reader.Read on the wrapped reader, allowing for interruption from a cancellation of the context.

type ContextualWriterWrapper

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

ContextualWriterWrapper is a wrapper around an existing io.Writer that allows for the interruption of writes with the cancellation of a context.

func NewContextualWriterWrapper

func NewContextualWriterWrapper(ctx context.Context, writer io.Writer) *ContextualWriterWrapper

NewContextualWriterWrapper initializes a new ContextualWriterWrapper.

func (*ContextualWriterWrapper) Write

func (c *ContextualWriterWrapper) Write(p []byte) (n int, err error)

Write calls Write on the wrapped writer, allowing for interruption from a cancellation of the context.

Jump to

Keyboard shortcuts

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