Files
2025-04-25 11:20:31 +03:00

84 lines
1.3 KiB
Go

package fs
import (
"io"
"os"
"path/filepath"
)
type sys struct {
}
type sysInode struct {
path string
}
func (s *sysInode) RemoveAll() error {
return os.RemoveAll(s.path)
}
func (s *sysInode) Join(path ...string) INode {
return &sysInode{
path: filepath.Join(path...),
}
}
func (s *sysInode) MakeDirs() error {
return os.MkdirAll(s.path, 0755)
}
func (s *sysInode) Parent() INode {
return &sysInode{
path: filepath.Dir(s.path),
}
}
func (s *sysInode) ReadIntoBytes() ([]byte, error) {
return os.ReadFile(s.path)
}
func (s *sysInode) OpenReadStream() (io.ReadCloser, error) {
f, err := os.Open(s.path)
if err != nil {
return nil, err
}
return f, nil
}
func (s *sysInode) OpenWriteStream() (io.WriteCloser, error) {
return os.OpenFile(s.path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
}
func (s *sysInode) Stat() (os.FileInfo, error) {
return os.Stat(s.path)
}
func (s *sysInode) IsExists() bool {
if _, err := os.Stat(s.path); os.IsNotExist(err) {
return false
}
return true
}
func (s *sysInode) Name() string {
return filepath.Base(s.path)
}
func (s *sysInode) AbsolutePath() string {
abs, err := filepath.Abs(s.path)
if err != nil {
return s.path
}
return abs
}
func (s *sys) INodeAt(path string) INode {
return &sysInode{
path: path,
}
}
var (
System FileSystem = &sys{}
)