zio

package
v0.0.0-...-d785515 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package zio implements some I/O utility functions.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCopyTreeOptions = &CopyTreeOptions{
	Symlinks:               false,
	Ignore:                 nil,
	CopyFunction:           Copy,
	IgnoreDanglingSymlinks: false,
}

DefaultCopyTreeOptions is used when the options to CopyTree() is nil.

Functions

func ChangedFrom

func ChangedFrom(file, base string) bool

Newer reports if the file's mtime is more recent than base.

func Copy

func Copy(src, dst string, modes Modes) error

Copy data and the given mode bits; this is the same as a CopyData() followed by a CopyMode().

The destination may be a directory, in which case the file name of "src" is used in that directory (as with "cp").

TODO: we can make this a bit more efficient by not duplicating all the checks in CopyData() and CopyMode().

func CopyData

func CopyData(src, dst string) error

CopyData copies the file data from the file in src to the path in dst.

Note that this only copies data; permissions and other special file bits may get lost.

func CopyMode

func CopyMode(src, dst string, modes Modes) error

CopyMode copies the given modes from src to dst.

func CopyTree

func CopyTree(src, dst string, options *CopyTreeOptions) error

CopyTree recursively copies a directory tree.

The destination directory must not already exist.

If the optional Symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied. If the file pointed by the symlink doesn't exist, an error will be returned.

You can set the optional IgnoreDanglingSymlinks flag to true if you want to silence this error. Notice that this has no effect on platforms that don't support os.Symlink.

The optional ignore argument is a callable. If given, it is called with the `src` parameter, which is the directory being visited by CopyTree(), and `names` which is the list of `src` contents, as returned by os.ReadDir():

callable(src, entries) -> ignoredNames

Since CopyTree() is called recursively, the callable will be called once for each directory that is copied. It returns a list of names relative to the `src` directory that should not be copied.

The optional copyFunction argument is a callable that will be used to copy each file. It will be called with the source path and the destination path as arguments. By default, Copy() is used, but any function that supports the same signature (like Copy2() when it exists) can be used.

func DumpReader

func DumpReader(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)

DumpReader reads all of b to memory and then returns two equivalent ReadClosers which will yield the same bytes.

This is useful if you want to read data from an io.Reader more than once.

It returns an error if the initial reading of all bytes fails. It does not attempt to make the returned ReadClosers have identical error-matching behavior.

This is based on httputil.DumpRequest, see zio.DumpBody() for an example usage.

Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file: https://golang.org/LICENSE

func Exists

func Exists(path string) bool

Exists reports if a path exists.

func IsSameFile

func IsSameFile(src string, dst string) error

IsSameFile reports if two files refer to the same file object. It will return a ErrSameFile if it is.

It is not an error if one of the two files doesn't exist.

func IsSpecialFile

func IsSpecialFile(fi os.FileInfo) error

IsSpecialFile reports if this file is a special file.

For example a named pipe, device file, or socket. If so it will return a ErrSpecialFile.

func IsSymlink(fi os.FileInfo) bool

IsSymlink reports if this file is a symbolic link.

func NopCloser

func NopCloser(r io.Writer) io.WriteCloser

NopCloser returns a WriteCloser with a no-op Close method.

Types

type CopyTreeOptions

type CopyTreeOptions struct {
	Symlinks               bool
	IgnoreDanglingSymlinks bool
	CopyFunction           func(string, string, Modes) error
	Ignore                 func(string, []fs.DirEntry) []string
}

CopyTreeOptions are flags for the CopyTree function.

type ErrExists

type ErrExists struct {
	Dst string
}

ErrExists is used when the destination already exists.

func (ErrExists) Error

func (e ErrExists) Error() string

type ErrNotDir

type ErrNotDir struct {
	Src string
}

ErrNotDir is used when attempting to copy a directory tree that is not a directory.

func (ErrNotDir) Error

func (e ErrNotDir) Error() string

type ErrSameFile

type ErrSameFile struct {
	Src string
	Dst string
}

ErrSameFile is used when the source and destination file are the same file.

func (ErrSameFile) Error

func (e ErrSameFile) Error() string

type ErrSpecialFile

type ErrSpecialFile struct {
	FileInfo os.FileInfo
}

ErrSpecialFile is used when the source or destination file is a special file, and not something we can operate on.

func (ErrSpecialFile) Error

func (e ErrSpecialFile) Error() string

type Modes

type Modes struct {
	Permissions bool // chmod
	Owner       bool // chown
	Mtime       bool // mtime
}

Modes to copy with CopyMode() and Copy().

type NopWriter

type NopWriter struct{}

NopWriter is an io.Writer that does nothing.

func (*NopWriter) Write

func (w *NopWriter) Write(b []byte) (int, error)

Write is a stub.

Jump to

Keyboard shortcuts

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