feat: Initial
This commit is contained in:
commit
f0abca60db
26 files changed
+1112
No files matched your search
@@ -0,0 +1,83 @@
|
||||
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{}
|
||||
)
|
||||
Reference in new issue
Block a user