Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 1.64 KB

Readme.md

File metadata and controls

85 lines (61 loc) · 1.64 KB

ioutil - AbsFs FileSystem Utility Functions

Package github.com/absfs/ioutil implements the standard library ioutil functions for the absfs.FileSystem interface.

Examples

Read directory.

fs, _ := osfs.NewFS()

files, err := ioutil.ReadDir(fs, ".")
if err != nil {
  log.Fatal(err)
}

for _, file := range files {
  fmt.Println(file.Name())
}

Temp Directory.

fs, _ := osfs.NewFS()
content := []byte("temporary file's content")
dir, err := ioutil.TempDir(fs, "", "example")
if err != nil {
  log.Fatal(err)
}

defer fs.RemoveAll(dir) // clean up

tmpfn := filepath.Join(dir, "tmpfile")
if err := ioutil.WriteFile(fs, tmpfn, content, 0666); err != nil {
  log.Fatal(err)
}

Temp file.

fs, _ := osfs.NewFS()
content := []byte("temporary file's content")
tmpfile, err := ioutil.TempFile(fs, "", "example")
if err != nil {
  log.Fatal(err)
}

defer fs.Remove(tmpfile.Name()) // clean up

if _, err := tmpfile.Write(content); err != nil {
  log.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
  log.Fatal(err)
}

Read file.

  fs, _ := osfs.NewFS()

  content, err := ioutil.ReadFile(fs, "testdata/hello")
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("File contents: %s", content)

  // Output:
  // File contents: Hello, Gophers!

absfs

Check out the absfs repo for more information about the abstract filesystem interface and features like filesystem composition

LICENSE

Because this project is derived from from the Go standard library it is governed by the Go license which is a BSD-style License. See LICENSE