fs

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: Apache-2.0, BSD-3-Clause, CC-BY-4.0, + 2 more Imports: 15 Imported by: 1

Documentation

Overview

Package fs provides filesystem operations.

To get a handle to existing fs-entry, you can use:

  • `fs.GetFileHandle(path string)` for a file handle
  • `fs.GetDirHandle(path string)` for a directory handle

this operations fail if the request entry does not exists.

To get or create a directory handle use

  • `fs.GetOrCreateDirHandle(path string, perm os.FilePerm)`
  • `fs.GetOrCreateSubDirHandle(name string, perm os.FilePerm)`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirHandle

type DirHandle struct {
	FSHandle
}

DirHandle represents a directory

func CacheDir

func CacheDir() (DirHandle, error)

CacheDir returns the user-local cache directory

func ConfigDir

func ConfigDir() (DirHandle, error)

ConfigDir returns the user-local config directory

func GetDirHandle

func GetDirHandle(path string) (DirHandle, error)

GetDirHandle returns a handle to a existing directory. If the directory does not exists, a error is returned.

func GetOrCreateDirHandle

func GetOrCreateDirHandle(path string, perm os.FileMode) (DirHandle, error)

GetOrCreateDirHandle returns a handle to a existing or a new created directory.

func TempDir

func TempDir() (DirHandle, error)

TempDir returns the directory for temporary files

func (*DirHandle) CreateArchive

func (self *DirHandle) CreateArchive(name string) (FileHandle, error)

func (*DirHandle) GetFileHandle

func (self *DirHandle) GetFileHandle(name string) (FileHandle, error)

GetFileHandle returns a handle to a existing file in the current dir-handle

func (*DirHandle) GetOrCreateSubDirHandle

func (self *DirHandle) GetOrCreateSubDirHandle(name string, perm os.FileMode) (DirHandle, error)

GetOrCreateSubDirHandle returns a handle to a existing or a new created child-dir of the current dir-handle.

func (*DirHandle) GetSubDirHandle

func (self *DirHandle) GetSubDirHandle(name string) (DirHandle, error)

GetSubDirHandle returns a child-dir of the current dir-handle. This operation fails if the requested directory does not exists.

func (*DirHandle) Ls

func (self *DirHandle) Ls() ([]FSHandle, error)

Ls returns a directory listing of the current dir-handle. Directory and filenames are grouped and sorted by names.

func (*DirHandle) ReadFile

func (self *DirHandle) ReadFile(name string) ([]byte, error)

ReadFile reads a child-file of the current dir-handle.

func (*DirHandle) WriteFile

func (self *DirHandle) WriteFile(name string, data []byte, perm os.FileMode) (FileHandle, error)

WriteFile creates or overrides a child-file of the current dir-handle

type FSHandle

type FSHandle struct {
	Name  string    `json:"name"`
	Path  string    `json:"path"`
	Kind  Kind      `json:"kind"`
	Size  int64     `json:"size"`
	MTime time.Time `json:"mtime"`
}

FSHandle represents a handle to a filesystem entry

This can be a file, a directory or anything else.

func GetFSHandle

func GetFSHandle(path string) (FSHandle, error)

GetFSHandle

func (*FSHandle) AsDirHandle

func (self *FSHandle) AsDirHandle() (DirHandle, error)

func (*FSHandle) AsFileHandle

func (self *FSHandle) AsFileHandle() (FileHandle, error)

func (*FSHandle) Dir

func (self *FSHandle) Dir() (DirHandle, error)

func (*FSHandle) Dirname

func (self *FSHandle) Dirname() string

func (*FSHandle) Move

func (self *FSHandle) Move(path string) error

func (*FSHandle) Rename

func (self *FSHandle) Rename(name string) error

type FileHandle

type FileHandle struct {
	FSHandle
}

FileHandle represents a file

func GetFileHandle

func GetFileHandle(path string) (FileHandle, error)

GetFileHandle returns a handle to a existing file. If the file does not exists, a error is returned. To create a file, use 'DirHandle.WriteFile'.

func (*FileHandle) Backup

func (self *FileHandle) Backup() (string, error)

Backup create a backup of the file in the backup location.

func (*FileHandle) Copy

func (fh *FileHandle) Copy(path string) (err error)

Copy copies a file.

func (*FileHandle) CopyTo

func (self *FileHandle) CopyTo(w io.Writer) error

CopyTo copies the whole file content into a given writer.

func (*FileHandle) MimeType

func (self *FileHandle) MimeType() (string, error)

MimeType returns file mime-type. This functions makes io-operations to read a part of the file.

func (*FileHandle) Read

func (self *FileHandle) Read() ([]byte, error)

Read returns the whole file content as a byte array.

func (*FileHandle) ReadString

func (self *FileHandle) ReadString() (string, error)

ReadString returns the whole file content as a string.

func (*FileHandle) Remove

func (self *FileHandle) Remove() error

Remove deletes the file

type Kind

type Kind int
const (
	DIR Kind = iota
	LINK
	PIPE
	SOCKET
	DEV
	FILE
)

func KindFromFileInfo

func KindFromFileInfo(fileInfo os.FileInfo) Kind

func (Kind) MarshalJSON

func (self Kind) MarshalJSON() ([]byte, error)

func (Kind) String

func (self Kind) String() string

func (*Kind) UnmarshalJSON

func (self *Kind) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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