Path: blob/main/vendor/github.com/spf13/afero/afero.go
2875 views
// Copyright © 2014 Steve Francia <[email protected]>.1// Copyright 2013 tsuru authors. All rights reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314// Package afero provides types and methods for interacting with the filesystem,15// as an abstraction layer.1617// Afero also provides a few implementations that are mostly interoperable. One that18// uses the operating system filesystem, one that uses memory to store files19// (cross platform) and an interface that should be implemented if you want to20// provide your own filesystem.2122package afero2324import (25"errors"26"io"27"os"28"time"29)3031type Afero struct {32Fs33}3435// File represents a file in the filesystem.36type File interface {37io.Closer38io.Reader39io.ReaderAt40io.Seeker41io.Writer42io.WriterAt4344Name() string45Readdir(count int) ([]os.FileInfo, error)46Readdirnames(n int) ([]string, error)47Stat() (os.FileInfo, error)48Sync() error49Truncate(size int64) error50WriteString(s string) (ret int, err error)51}5253// Fs is the filesystem interface.54//55// Any simulated or real filesystem should implement this interface.56type Fs interface {57// Create creates a file in the filesystem, returning the file and an58// error, if any happens.59Create(name string) (File, error)6061// Mkdir creates a directory in the filesystem, return an error if any62// happens.63Mkdir(name string, perm os.FileMode) error6465// MkdirAll creates a directory path and all parents that does not exist66// yet.67MkdirAll(path string, perm os.FileMode) error6869// Open opens a file, returning it or an error, if any happens.70Open(name string) (File, error)7172// OpenFile opens a file using the given flags and the given mode.73OpenFile(name string, flag int, perm os.FileMode) (File, error)7475// Remove removes a file identified by name, returning an error, if any76// happens.77Remove(name string) error7879// RemoveAll removes a directory path and any children it contains. It80// does not fail if the path does not exist (return nil).81RemoveAll(path string) error8283// Rename renames a file.84Rename(oldname, newname string) error8586// Stat returns a FileInfo describing the named file, or an error, if any87// happens.88Stat(name string) (os.FileInfo, error)8990// The name of this FileSystem91Name() string9293// Chmod changes the mode of the named file to mode.94Chmod(name string, mode os.FileMode) error9596// Chown changes the uid and gid of the named file.97Chown(name string, uid, gid int) error9899// Chtimes changes the access and modification times of the named file100Chtimes(name string, atime time.Time, mtime time.Time) error101}102103var (104ErrFileClosed = errors.New("File is closed")105ErrOutOfRange = errors.New("out of range")106ErrTooLarge = errors.New("too large")107ErrFileNotFound = os.ErrNotExist108ErrFileExists = os.ErrExist109ErrDestinationExists = os.ErrExist110)111112113