fs

package
v0.0.0-...-17143bd Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fs provides filesystem utilities for ghx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies the given file from src to dst.

func EnsureDir

func EnsureDir(dir string) error

EnsureDir ensures that the given directory exists under the ghx data home directory.

func EnsureFile

func EnsureFile(file string) error

EnsureFile ensures that the given file exists under the ghx data home directory. If the file does not exist, it will be created.

To ensure everything is working as expected, the method will also ensure that the directory of the file exists.

func Exists

func Exists(path string) (bool, error)

Exists checks if the given path exists.

func ReadJSONFile

func ReadJSONFile[T any](file string, val *T) error

ReadJSONFile reads the given path as a JSON file under the ghx data home directory and unmarshal it into the given value.

func ReadYAMLFile

func ReadYAMLFile[T any](file string, val *T) error

ReadYAMLFile reads the given path as a YAML file.

func WriteFile

func WriteFile(file string, content []byte, permissions os.FileMode) error

WriteFile ensures that the given file exists under the ghx data home directory. If the file does not exist, it will be created and the given content will be written to it.

To ensure everything is working as expected, the method will also ensure that the directory of the file exists.

func WriteJSONFile

func WriteJSONFile(file string, val interface{}) error

WriteJSONFile writes the given value to the given path as a JSON file under the ghx data home directory.

Types

type MultipartFileWriter

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

MultipartFileWriter allows writing a file in chunks first and then merging the chunks into a single file. This is useful for uploading large files in chunks while ensuring files are not corrupted in case of network errors or not ordered chunk uploads.

func NewMultipartFileWriter

func NewMultipartFileWriter(root string) (*MultipartFileWriter, error)

NewMultipartFileWriter creates a new MultipartFileWriter that writes files to the specified root directory.

func (*MultipartFileWriter) Merge

func (w *MultipartFileWriter) Merge() error

Merge combines the uploaded part files into separate intended files and removes the part files.

func (*MultipartFileWriter) Write

func (w *MultipartFileWriter) Write(filePath string, offset int, data io.Reader) error

Write saves the uploaded part data as separate files in the same directory as the specified file.

Jump to

Keyboard shortcuts

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