Skip to content

Package blobfs provides access with fs.FS interface to files stored in a blob storage.

License

Notifications You must be signed in to change notification settings

ichizero/blobfs

Repository files navigation

blobfs

test Go Reference Codecov Go Report Card

Package blobfs provides access with fs.FS interface to files stored in a blob storage.

FS implements fs.FS, so it can be used with any packages that understands file system interfaces.

e.g.) net/http, text/template, html/template

It uses gocloud.dev/blob for a blob backend, so it can read the following blob storages.

  • Google Cloud Storage
  • Amazon S3
  • Azure Blob Storage
  • Local filesystem
  • In memory filesystem

For more details about gocloud.dev/blob, please refer to the following page. ref.) https://gocloud.dev/howto/blob/

Example

package blobfs_test

import (
	"context"
	"fmt"
	"io"
	"log"
	"os"

	"gocloud.dev/blob"
	_ "gocloud.dev/blob/fileblob"

	"github.com/ichizero/blobfs"
)

func Example_fileblob() {
	ctx := context.Background()
	dir, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	bucket, err := blob.OpenBucket(ctx, fmt.Sprintf("file://%s/testdata", dir))
	if err != nil {
		log.Fatal(err)
	}

	fsys := blobfs.New(bucket)
	f, err := fsys.Open("foo.txt")
	b, err := io.ReadAll(f)
	if err != nil {
		if err != io.EOF {
			log.Fatal(err)
		}
	}
	log.Print(string(b))
}

About

Package blobfs provides access with fs.FS interface to files stored in a blob storage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages