FILE / ScuroNeko/mtg

ipblocklist/files/local.go

Исходный файл и его история в репозитории.
FILE 4dca1d2b071a3b33ff068220840647743dd525de
Files
mtg/ipblocklist/files/local.go
T
2022-08-08 15:54:38 +03:00

32 lines
593 B
Go

package files
import (
"context"
"fmt"
"io"
"os"
)
type localFile struct {
path string
}
func (l localFile) Open(ctx context.Context) (io.ReadCloser, error) {
return os.Open(l.path) //nolint: wrapcheck
}
func (l localFile) String() string {
return l.path
}
// NewLocal returns an openable File for a path on a local file system.
func NewLocal(path string) (File, error) {
if stat, err := os.Stat(path); os.IsNotExist(err) || stat.IsDir() || stat.Mode().Perm()&0o400 == 0 {
return nil, fmt.Errorf("%s is not a readable file", path)
}
return localFile{
path: path,
}, nil
}