Created
September 7, 2020 20:50
-
-
Save LandonTClipp/8a964a34fa6cb3d0cedb547cfe7a7d29 to your computer and use it in GitHub Desktop.
github.com/chigopher/pathlib in-memory example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/chigopher/pathlib" | |
"github.com/spf13/afero" | |
) | |
func main() { | |
// Create a path using an in-memory filesystem | |
path := pathlib.NewPathAfero("/", afero.NewMemMapFs()) | |
hello := path.Join("hello_world.txt") | |
hello.WriteFile([]byte("hello world!"), 0o644) | |
subpaths, err := path.ReadDir() | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
os.Exit(1) | |
} | |
for _, subpath := range subpaths { | |
fmt.Printf("Name: %s Mode: %o Size: %d\n", subpath.Name(), subpath.Mode(), subpath.Size()) | |
} | |
bytes, _ := hello.ReadFile() | |
fmt.Println(string(bytes)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment