blobbucket

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

GoDoc Go Report Card

Blob Bucket

Blob Bucket is an implementation of Bucket with Go-Cloud Blob interface.

Please refer to the FSDB project for more background information.

(Example code on godoc)

License

BSD License.

Documentation

Overview

Package blobbucket provides an implementation of FSDB Bucket using Go-Cloud Blob interface.

Example
package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strings"

	"github.com/fishy/blobbucket"
	"gocloud.dev/blob/fileblob"
)

func main() {
	dir, err := ioutil.TempDir("", "blob-bucket-test")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(dir)
	fs, err := fileblob.OpenBucket(dir, nil)
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	bkt := blobbucket.Open(fs)
	obj := "test/object"
	content := `Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.`

	_, err = bkt.Read(ctx, obj)
	fmt.Println("Read IsNotExist:", bkt.IsNotExist(err))

	if err := bkt.Write(ctx, obj, strings.NewReader(content)); err != nil {
		log.Fatal(err)
	}
	reader, err := bkt.Read(ctx, obj)
	if err != nil {
		log.Fatal(err)
	}
	defer reader.Close()
	buf, err := ioutil.ReadAll(reader)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Content unchanged:", content == string(buf))
	if err := bkt.Delete(ctx, obj); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Delete IsNotExist:", bkt.IsNotExist(bkt.Delete(ctx, obj)))
}
Output:

Read IsNotExist: true
Content unchanged: true
Delete IsNotExist: true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobBucket

type BlobBucket struct {
	// contains filtered or unexported fields
}

BlobBucket is an implementation of FSDB Bucket with Go-Cloud Blob interface.

func Open

func Open(bkt *blob.Bucket) *BlobBucket

Open opens a blob bucket.

func (*BlobBucket) Delete

func (bkt *BlobBucket) Delete(ctx context.Context, name string) error

Delete deletes an object from the bucket.

func (*BlobBucket) IsNotExist

func (bkt *BlobBucket) IsNotExist(err error) bool

IsNotExist checks whether err is storage.ErrObjectNotExist.

func (*BlobBucket) Read

func (bkt *BlobBucket) Read(
	ctx context.Context,
	name string,
) (io.ReadCloser, error)

func (*BlobBucket) Write

func (bkt *BlobBucket) Write(
	ctx context.Context,
	name string,
	data io.Reader,
) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL