ioutilh

package
v1.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package ioutilh provides some helper functions and types to simplify working with ioutil package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDirEmpty

func IsDirEmpty(dirName string) (bool, error)

IsDirEmpty checks if directory named by dirName is empty (has no child).

func Read

func Read(r io.Reader, p ...[]byte) (n int, err error)

Read perform ReadFull but with variable number of arguments. It stops if unable to fully read some of p. Read returns number of successfully read p's and error. It always returns nil error if EOF has been reached or if all p's have been read. Where is no way to check how many bytes have been read if not all p's have been read successfully.

func ReadDirNames

func ReadDirNames(dirName string, arrange bool) ([]string, error)

ReadDirNames reads the directory named by dirName and returns list of directory entries. Result slice will be sorted if arrange is set to true.

func ReadFull

func ReadFull(r io.Reader, p []byte) (n int, err error)

ReadFull reads up to len(p) bytes into p. It is like io.Reader.Read but it tries to read full p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if ReadFull returns n < len(p), it may use all of p as scratch space during the call. If some data is available but less than len(p) bytes, ReadFull waits for more. ReadFull finished (on any of): - after len(p) bytes will be read (returns <len(p), nil> ), - if EOF will be reached (returns <n, nil> ), - on any other error (returns <n, err>). ReadFull does not return any error if len(p) bytes have been read. Warning: ReadFull can waste CPU because of io.Reader.Read may returns zero bytes even without error (depends on Reader implementation). In that case ReadFull will not block internally but will try to get new bytes in loop.

func Write

func Write(w io.Writer, data ...[]byte) (int, error)

Write is like io.Writer.Write but with variable number of arguments. Write stops writing after first error. Returns number of successfully wrote arguments and error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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