ZRY 2 months ago
parent
commit
deffae3499
10 changed files with 104 additions and 0 deletions
  1. 8 0
      .idea/.gitignore
  2. 9 0
      .idea/FsUtils.iml
  3. 7 0
      .idea/misc.xml
  4. 8 0
      .idea/modules.xml
  5. 6 0
      .idea/vcs.xml
  6. 3 0
      iofswrap/README.md
  7. 7 0
      iofswrap/go.mod
  8. 4 0
      iofswrap/go.sum
  9. 28 0
      iofswrap/iofs_file.go
  10. 24 0
      iofswrap/iofs_wrap.go

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
.idea/FsUtils.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 7 - 0
.idea/misc.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="XMakeProjectSettings">
+    <option name="currentArchitecture" value="x86" />
+    <option name="workingDirectory" value="$PROJECT_DIR$" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/FsUtils.iml" filepath="$PROJECT_DIR$/.idea/FsUtils.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 3 - 0
iofswrap/README.md

@@ -0,0 +1,3 @@
+# iofswrap
+
+Simply wrap `github.com/spf13/afero` `afero.Fs` to `io/fs` `fs.Fs`

+ 7 - 0
iofswrap/go.mod

@@ -0,0 +1,7 @@
+module git.swzry.com/ProjectNagae/FsUtils/iofswrap
+
+go 1.21
+
+require github.com/spf13/afero v1.11.0
+
+require golang.org/x/text v0.14.0 // indirect

+ 4 - 0
iofswrap/go.sum

@@ -0,0 +1,4 @@
+github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
+github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
+golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
+golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

+ 28 - 0
iofswrap/iofs_file.go

@@ -0,0 +1,28 @@
+package iofswrap
+
+import (
+	"github.com/spf13/afero"
+	"io/fs"
+)
+
+var _ fs.File = (*IOFSFileWrapper)(nil)
+
+func NewFileWrapper(afile afero.File) fs.File {
+	return &IOFSFileWrapper{afile: afile}
+}
+
+type IOFSFileWrapper struct {
+	afile afero.File
+}
+
+func (w IOFSFileWrapper) Stat() (fs.FileInfo, error) {
+	return w.afile.Stat()
+}
+
+func (w IOFSFileWrapper) Read(bytes []byte) (int, error) {
+	return w.afile.Read(bytes)
+}
+
+func (w IOFSFileWrapper) Close() error {
+	return w.afile.Close()
+}

+ 24 - 0
iofswrap/iofs_wrap.go

@@ -0,0 +1,24 @@
+package iofswrap
+
+import (
+	"github.com/spf13/afero"
+	"io/fs"
+)
+
+var _ fs.FS = (*IOFSWrapper)(nil)
+
+type IOFSWrapper struct {
+	afs afero.Fs
+}
+
+func NewIOFSWrapper(afs afero.Fs) *IOFSWrapper {
+	return &IOFSWrapper{afs: afs}
+}
+
+func (w IOFSWrapper) Open(name string) (fs.File, error) {
+	f, err := w.afs.Open(name)
+	if err != nil {
+		return nil, err
+	}
+	return NewFileWrapper(f), nil
+}