Skip to content

Commit

Permalink
Merge pull request #7 from jarxorg/memfs
Browse files Browse the repository at this point in the history
Memfs
  • Loading branch information
mojatter authored Nov 9, 2021
2 parents 053520e + 3fc373b commit c940ee6
Show file tree
Hide file tree
Showing 7 changed files with 1,316 additions and 42 deletions.
44 changes: 3 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,10 @@

Go "io" and "io/fs" package utilities.

## Writable io/fs implementations for the OS
## Writable io/fs.FS implementations

```go
package main

import (
"fmt"
"io/fs"
"io/ioutil"
"log"
"os"

"github.com/jarxorg/io2"
"github.com/jarxorg/io2/osfs"
)

func func main() {
tmpDir, err := ioutil.TempDir("", "example")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(tmpDir)

name := "example.txt"
content := []byte(`Hello`)

fsys := osfs.DirFS(tmpDir)
_, err = io2.WriteFile(fsys, name, content, fs.ModePerm)
if err != nil {
log.Fatal(err)
}

wrote, err := ioutil.ReadFile(tmpDir + "/" + name)
if err != nil {
log.Fatal(err)
}

fmt.Printf("%s\n", string(wrote))

// Output: Hello
}
```
- [osfs](https://github.com/jarxorg/io2/tree/main/osfs)
- [memfs](https://github.com/jarxorg/io2/tree/main/memfs)

## Delegator

Expand Down
31 changes: 31 additions & 0 deletions memfs/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package memfs_test

import (
"fmt"
"log"
"io/fs"

"github.com/jarxorg/io2"
"github.com/jarxorg/io2/memfs"
)

func ExampleNew() {
name := "path/to/example.txt"
content := []byte(`Hello`)

fsys := memfs.New()
var err error
_, err = io2.WriteFile(fsys, name, content, fs.ModePerm)
if err != nil {
log.Fatal(err)
}

wrote, err := fs.ReadFile(fsys, name)
if err != nil {
log.Fatal(err)
}

fmt.Printf("%s\n", string(wrote))

// Output: Hello
}
Loading

0 comments on commit c940ee6

Please sign in to comment.