package file

import "github.com/IBM/fp-go/ioeither/file"

Index

Variables

var (
	// Open opens a file for reading
	Open = IOE.Eitherize1(os.Open)
	// Create opens a file for writing
	Create = IOE.Eitherize1(os.Create)
	// ReadFile reads the context of a file
	ReadFile = IOE.Eitherize1(os.ReadFile)
)
var (
	// CreateTemp created a temp file with proper parametrization
	CreateTemp = IOE.Eitherize2(os.CreateTemp)
)

Functions

func Close

func Close[C io.Closer](c C) IOE.IOEither[error, any]

Close closes an object

func Mkdir

func Mkdir(path string, perm os.FileMode) IOE.IOEither[error, string]

Mkdir create a directory, see os.Mkdir

func MkdirAll

func MkdirAll(path string, perm os.FileMode) IOE.IOEither[error, string]

MkdirAll create a sequence of directories, see os.MkdirAll

func ReadAll

func ReadAll[R io.ReadCloser](acquire IOE.IOEither[error, R]) IOE.IOEither[error, []byte]

ReadAll uses a generator function to create a stream, reads it and closes it

func Remove

func Remove(name string) IOE.IOEither[error, string]

Remove removes a file by name

func WithTempFile

func WithTempFile[A any](f func(*os.File) IOE.IOEither[error, A]) IOE.IOEither[error, A]

WithTempFile creates a temporary file, then invokes a callback to create a resource based on the file, then close and remove the temp file

func Write

func Write[R any, W io.WriteCloser](acquire IOE.IOEither[error, W]) func(use func(W) IOE.IOEither[error, R]) IOE.IOEither[error, R]

Write uses a generator function to create a stream, writes data to it and closes it

func WriteAll

func WriteAll[W io.WriteCloser](data []byte) func(acquire IOE.IOEither[error, W]) IOE.IOEither[error, []byte]

WriteAll uses a generator function to create a stream, writes data to it and closes it

func WriteFile

func WriteFile(dstName string, perm os.FileMode) func([]byte) IOE.IOEither[error, []byte]

WriteFile writes a data blob to a file

Source Files

dir.go file.go readall.go tempfile.go write.go

Version
v1.0.151 (latest)
Published
Nov 23, 2024
Platform
linux/amd64
Imports
7 packages
Last checked
5 months ago

Tools for package owners.