Documentation ¶
Overview ¶
Package ioutilx implements some I/O utility functions.
Index ¶
- Variables
- func Copy(src, dst string, modes Modes) error
- func CopyData(src, dst string) error
- func CopyMode(src, dst string, modes Modes) error
- func CopyTree(src, dst string, options *CopyTreeOptions) error
- func DumpReader(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)
- func IsSameFile(src string, dst string) error
- func IsSpecialFile(fi os.FileInfo) error
- func IsSymlink(fi os.FileInfo) bool
- type CopyTreeOptions
- type ErrExists
- type ErrNotDir
- type ErrSameFile
- type ErrSpecialFile
- type Modes
Constants ¶
This section is empty.
Variables ¶
var DefaultCopyTreeOptions = &CopyTreeOptions{ Symlinks: false, Ignore: nil, CopyFunction: Copy, IgnoreDanglingSymlinks: false, }
DefaultCopyTreeOptions is used when the options to CopyTree() is nil.
Functions ¶
func Copy ¶
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 ¶
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 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 ioutil.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 github.com/teamwork/ioutilx.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 IsSameFile ¶
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 ¶
IsSpecialFile reports if this file is a special file such as a named pipe, device file, or socket. If so it will return a ErrSpecialFile.
Types ¶
type CopyTreeOptions ¶
type CopyTreeOptions struct { Symlinks bool IgnoreDanglingSymlinks bool CopyFunction func(string, string, Modes) error Ignore func(string, []os.FileInfo) []string }
CopyTreeOptions are flags for the CopyTree function.
type ErrExists ¶
type ErrExists struct {
Dst string
}
ErrExists is used when the destination already exists.
type ErrNotDir ¶
type ErrNotDir struct {
Src string
}
ErrNotDir is used when attempting to copy a directory tree that is not a directory.
type ErrSameFile ¶
ErrSameFile is used when the source and destination file are the same file.
func (ErrSameFile) Error ¶
func (e ErrSameFile) Error() string
type ErrSpecialFile ¶
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