This commit is contained in:
royalcat 2024-06-02 22:53:33 +03:00
parent d056ac1167
commit bd75492b02
81 changed files with 822 additions and 1098 deletions
pkg/ctxbilly

View file

@ -5,7 +5,7 @@ import (
"io"
"os"
"git.kmsign.ru/royalcat/tstor/pkg/ctxio"
"github.com/royalcat/ctxio"
)
type Filesystem interface {
@ -36,16 +36,6 @@ type Filesystem interface {
// UNC path if and only if the first path element is a UNC path.
Join(elem ...string) string
// TempFile creates a new temporary file in the directory dir with a name
// beginning with prefix, opens the file for reading and writing, and
// returns the resulting *os.File. If dir is the empty string, TempFile
// uses the default directory for temporary files (see os.TempDir).
// Multiple programs calling TempFile simultaneously will not choose the
// same file. The caller can use f.Name() to find the pathname of the file.
// It is the caller's responsibility to remove the file when no longer
// needed.
TempFile(ctx context.Context, dir, prefix string) (File, error)
// ReadDir reads the directory named by d(irname and returns a list of
// directory entries sorted by filename.
ReadDir(ctx context.Context, path string) ([]os.FileInfo, error)
@ -74,19 +64,38 @@ type Filesystem interface {
// Root() string
}
type TempFileFS interface {
// TempFile creates a new temporary file in the directory dir with a name
// beginning with prefix, opens the file for reading and writing, and
// returns the resulting *os.File. If dir is the empty string, TempFile
// uses the default directory for temporary files (see os.TempDir).
// Multiple programs calling TempFile simultaneously will not choose the
// same file. The caller can use f.Name() to find the pathname of the file.
// It is the caller's responsibility to remove the file when no longer
// needed.
TempFile(ctx context.Context, dir, prefix string) (File, error)
}
type File interface {
// Name returns the name of the file as presented to Open.
Name() string
ctxio.Writer
ctxio.WriterAt
ctxio.Reader
ctxio.ReaderAt
io.Seeker
ctxio.Closer
}
type LockFile interface {
// Lock locks the file like e.g. flock. It protects against access from
// other processes.
Lock() error
// Unlock unlocks the file.
Unlock() error
}
type TruncateFile interface {
// Truncate the file.
Truncate(ctx context.Context, size int64) error
}