fs

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package fs provides a primitive virtual file system.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFileExtension = errors.New("invalid file extension")
)

Functions

func Abs added in v0.11.0

func Abs(paths ...string) []string

Abs makes paths absolute, when not absolute already.

func Content added in v0.9.1

func Content(path string) ([]byte, error)

Content returns the content of (virtual) file specified by path.

func FindASN1Files

func FindASN1Files(dir string) []string

FindASN1Files returns a list of ASN.1 files (.asn, asn1).

func FindCFiles

func FindCFiles(dir string) []string

FindCFiles returns a list of C/C++ files (.c, .cc, .cxx, .cpp).

func FindFilesRecursive added in v0.9.1

func FindFilesRecursive(dir string) []string

FindFilesRecursive returns a list files from the whole directory subtree.

func FindK3EnvInCurrPath added in v0.9.1

func FindK3EnvInCurrPath(dir string) string

FindK3EnvInCurrPath returns the path of the directory containing k3.env

func FindTTCN3DirectoriesRecursive added in v0.9.2

func FindTTCN3DirectoriesRecursive(dir string) []string

FindTTCN3DirectoriesRecursive returns a list of directories containing TTCN-3 source files.

func FindTTCN3Files

func FindTTCN3Files(dir string) []string

FindTTCN3Files returns a list of TTCN-3 source files (.ttcn3, .ttcn, .ttcnpp) in the given directory.

func FindTTCN3FilesRecursive added in v0.9.2

func FindTTCN3FilesRecursive(dir string) []string

FindTTCN3FilesRecursive returns a list TTCN-3 source files available in directory sub-tree.

func Glob added in v0.9.1

func Glob(s string) []string

Glob is a wrapper for filepath.Glob, but ignoring any errors.

func HasASN1Extension

func HasASN1Extension(file string) bool

HasASN1Extension returns true if file has suffix .asn or .asn1

func HasCExtension

func HasCExtension(file string) bool

HasCExtension returns true if file has suffix .c, .cc, .cxx or .cpp

func HasTTCN3Extension

func HasTTCN3Extension(file string) bool

HasTTCN3Extension returns true if file has suffix .ttcn3 or .ttcn

func IsDir added in v0.9.1

func IsDir(path string) bool

IsDir returns true if path exists and is a directory.

func IsFsRoot added in v0.9.3

func IsFsRoot(path string) bool

IsFsRoot returns true if the supplied path coincides with the filesystem root

func IsRegular added in v0.9.1

func IsRegular(path string) bool

IsRegulart returns true if path exists and is a regular file.

func IsURI added in v0.16.2

func IsURI(s string) bool

func JoinPath added in v0.16.2

func JoinPath(baseUrl string, elem ...string) string

JoinPath joins any number of path elements into a single path, separating them with an OS specific Separator. Empty elements are ignored. The result is Cleaned. If the argument list is empty or all its elements are empty, JoinPath returns an empty string.

If baseUrl is an absolute URL, JoinPath will will keep the scheme of the first argument and separats the rest with a slash.

func Path added in v0.9.1

func Path(s string) string

Path returns a decoded file path when you pass a URI with file:// scheme.

func PathSlice

func PathSlice(files ...*File) []string

PathSlice returns a string slice of the File objects passed as argument.

func Real added in v0.9.1

func Real(base, path string) string

Real makes a path, which is relativ to base, to a real path.

func Rel added in v0.9.1

func Rel(base string, paths ...string) []string

Rel makes paths relative to base, when not absolute already. Use it when when you want to make a path relative to a test suite manifest.

func ReplaceExt added in v0.12.0

func ReplaceExt(path string, newExt string) string

func SetContent added in v0.9.1

func SetContent(path string, b []byte)

SetContent of (virtual) file specified by path.

func Slugify added in v0.9.1

func Slugify(s string) string

Slugify generates a slug from unicode string.

func Stem added in v0.9.1

func Stem(s string) string

Stems strips directory and extension from a string.

func TTCN3Files added in v0.9.2

func TTCN3Files(paths ...string) ([]string, error)

TTCN3Files takes a list of paths and replaces all paths describing a directory with the TTCN-3 files contained in that directory.

A error is returned for each path which is not accessable or for each (non-directory), which does not have a TTCN-3 extension.

This function a conventient way to "flatten" the Sources of a project.Config struct, for example.

func URI added in v0.9.1

func URI(path string) span.URI

URI turns paths into URIs

func WalkUp added in v0.9.1

func WalkUp(path string, f func(path string) bool)

WalkUp traverses a path towards file system root.

Types

type File

type File struct {

	// We export the handle until we have better alternatives for cache invalidation.
	Handle *memoize.Handle
	// contains filtered or unexported fields
}

A File represents a open file

func Open

func Open(path string) *File

Open a file.

path can be any identifier, URL, ...

func (*File) Bytes

func (f *File) Bytes() ([]byte, error)

Bytes returns the contents of File. If content was not specified using SetBytes, Bytes will try reading the file path's content from disk.

func (*File) Close

func (f *File) Close()

Closes a file and removes it from the store

func (*File) ID

func (f *File) ID() string

ID returns an identifier.

func (*File) Path

func (f *File) Path() string

Path returns the file system path (if possible).

func (*File) Reset

func (f *File) Reset()

Reset sets the content to zero. This is identcal to SetBytes(nil)

func (*File) SetBytes

func (f *File) SetBytes(b []byte)

SetBytes set the contents of the file.

func (*File) String

func (f *File) String() string

String returns the file path as it was using during creation: If File was created as URI, String will return an URI, if File was created as relative path, String will return this relative path.

func (*File) URI

func (f *File) URI() span.URI

URI returns returns the absolute file path with a "file://" prefix.

type Store

type Store struct {
	// contains filtered or unexported fields
}

A Store holds all open files.

func (*Store) Open

func (s *Store) Open(path string) *File

Open a file and add it to the store.

Jump to

Keyboard shortcuts

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