/s3fs

go io/fs implementation on S3

Primary LanguageGoMIT LicenseMIT

github.com/jarxorg/s3fs

PkgGoDev Report Card

Package s3fs provides an implementation of wfs for S3.

Examples

ReadDir

package main

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

  "github.com/jarxorg/s3fs"
)

func main() {
  fsys := s3fs.New("<your-bucket>")
  entries, err := fs.ReadDir(fsys, ".")
  if err != nil {
    log.Fatal(err)
  }
  for _, entry := range entries {
    fmt.Println(entry.Name())
  }
}

WriteFile

package main

import (
  "io/fs"
  "log"

  "github.com/jarxorg/wfs"
  "github.com/jarxorg/s3fs"
)

func main() {
  fsys := s3fs.New("<your-bucket>")
  _, err := wfs.WriteFile(fsys, "test.txt", []byte(`Hello`), fs.ModePerm)
  if err != nil {
    log.Fatal(err)
  }
}

Tests

S3FS can pass TestFS in "testing/fstest".

import (
  "testing/fstest"
  "github.com/jarxorg/s3fs"
)

// ...

fsys := s3fs.New("<your-bucket>")
if err := fstest.TestFS(fsys, "<your-expected>"); err != nil {
  t.Errorf("Error testing/fstest: %+v", err)
}

Integration tests

FSTEST_BUCKET="<your-bucket>" \
FSTEST_EXPECTED="<your-expected>" \
  go test -tags integtest ./...