fileutil

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Kilobyte represents the bytes in a kilobyte.
	Kilobyte int64 = 1 << 10
	// Megabyte represents the bytes in a megabyte.
	Megabyte int64 = Kilobyte << 10
	// Gigabyte represents the bytes in a gigabyte.
	Gigabyte int64 = Megabyte << 10
	//Terrabyte represents the bytes in a terrabyte.
	Terrabyte int64 = Gigabyte << 10
)

Variables

This section is empty.

Functions

func ETag

func ETag(contents []byte) (string, error)

ETag creates an etag for a given blob.

func FormatFileSize

func FormatFileSize(sizeBytes int64) string

FormatFileSize returns a string representation of a file size in bytes.

func ParseFileSize

func ParseFileSize(fileSizeValue string) int64

ParseFileSize parses a file size

func ReadChunks

func ReadChunks(filePath string, chunkSize int, handler func([]byte) error) error

ReadChunks reads a file in `chunkSize` pieces, dispatched to the handler.

func ReadLines

func ReadLines(filePath string, handler func(string) error) error

ReadLines reads a file and calls the handler for each line.

func RemoveMany

func RemoveMany(filePaths ...string) error

RemoveMany removes an array of files.

Types

type Temp

type Temp struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Temp is a file that deletes itself when closed. It does not hold a file handle open, so no guarantees are made around the file persisting for the lifetime of the object.

func NewTemp

func NewTemp(contents []byte) (*Temp, error)

NewTemp creates a new temp file with given contents.

func (*Temp) Close

func (tf *Temp) Close() error

Close closes the file reference and deletes the file.

func (*Temp) Name

func (tf *Temp) Name() string

Name returns the fully qualified file path.

func (*Temp) Read

func (tf *Temp) Read(buffer []byte) (int, error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.

func (*Temp) ReadAt

func (tf *Temp) ReadAt(buffer []byte, off int64) (int, error)

ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF.

func (*Temp) Stat

func (tf *Temp) Stat() (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

func (*Temp) Write

func (tf *Temp) Write(contents []byte) (int, error)

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).

func (*Temp) WriteAt

func (tf *Temp) WriteAt(contents []byte, off int64) (int, error)

WriteAt writes len(b) bytes to the File starting at byte offset off. It returns the number of bytes written and an error, if any. WriteAt returns a non-nil error when n != len(b).

func (*Temp) WriteString

func (tf *Temp) WriteString(contents string) (int, error)

WriteString is like Write, but writes the contents of string s rather than a slice of bytes.

Jump to

Keyboard shortcuts

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