regrid

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

README

ReGrid for GoRethink

GitHub tag GoDoc No Maintenance Intended

ReGrid is a method of storing large files inside a RethinkDB database, this library implements the ReGrid specification in Go.

Features
  • Reliable - Files are replicated across the cluster, benefiting from RethinkDB's automatic failover.
  • Scalable - Easily store large files in RethinkDB, distributed across the cluster.
  • Consistent - Sha256 hashes are calculated when the file is written, and verified when read back out.
  • Realtime - Watch the filesystem for changes and be notified immediately.

The ReGrid spec is an open specification free for anyone to implement and use.

Installation

go get -u github.com/dancannon/gorethink-regrid

Usage

package main

import (
    "fmt"
    "log"

    r "gopkg.in/dancannon/gorethink.v2"
    "github.com/dancannon/gorethink-regrid"
)

// Upload the local file "files/lipsum.txt" to RethinkDB under the filename
// "/docs/lipsum.txt"
func Example() {
    session, err := r.Connect(r.ConnectOpts{
        Address: url,
    })
    if err != nil {
        log.Fatalln(err)
    }

    bucket := regrid.New(session, regrid.BucketOptions{
        BucketName:   "example",
    })
    if err := bucket.Init(); err != nil {
        log.Fatalln(err)
    }

    dst, err := bucket.Create("/docs/lipsum.txt", nil)
    if err != nil {
        log.Fatalln(err)
    }
    defer dst.Close()

    src, err := os.Open("files/lipsum.txt")
    if err != nil {
        log.Fatalln(err)
    }
    defer src.Close()

    _, err = io.Copy(dst, src)
    if err != nil {
        log.Fatalln(err)
    }
}

Notes

Apologies for the lack of documentation however due to the closure of RethinkDB I have decided to halt the development of this library.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid          = errors.New("invalid argument")
	ErrNotExist         = errors.New("file does not exist")
	ErrRevisionNotExist = errors.New("revision does not exist")
	ErrHashMismatch     = errors.New("sha256 hash mismatch")
)

Functions

This section is empty.

Types

type Bucket

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

func New

func New(session *r.Session, options BucketOptions) *Bucket

func (*Bucket) Create

func (b *Bucket) Create(filename string, metadata map[string]interface{}) (*File, error)

func (*Bucket) Delete

func (b *Bucket) Delete(id string) error

func (*Bucket) HardDelete

func (b *Bucket) HardDelete(id string) error

func (*Bucket) Init

func (b *Bucket) Init() error

func (*Bucket) ListFilename

func (b *Bucket) ListFilename(filename string, skip, limit int, reverse bool) ([]*FileInfo, error)

func (*Bucket) ListMetadata

func (b *Bucket) ListMetadata(metadata map[string]interface{}, skip, limit int) ([]*FileInfo, error)

func (*Bucket) ListRegex

func (b *Bucket) ListRegex(pattern string, skip, limit int, reverse bool) ([]*FileInfo, error)

func (*Bucket) Open

func (b *Bucket) Open(filename string) (*File, error)

func (*Bucket) OpenID

func (b *Bucket) OpenID(id string) (*File, error)

func (*Bucket) OpenRevision

func (b *Bucket) OpenRevision(filename string, revision int) (*File, error)

func (*Bucket) Rename

func (b *Bucket) Rename(id, filename string) error

func (*Bucket) ReplaceMetadata

func (b *Bucket) ReplaceMetadata(id string, metadata map[string]interface{}) error

func (*Bucket) WatchFilename

func (b *Bucket) WatchFilename(filename string) (*r.Cursor, error)

func (*Bucket) WatchMetadata

func (b *Bucket) WatchMetadata(metadata map[string]interface{}) (*r.Cursor, error)

func (*Bucket) WatchRegex

func (b *Bucket) WatchRegex(pattern string) (*r.Cursor, error)

type BucketOptions

type BucketOptions struct {
	DatabaseName   string
	BucketName     string
	ChunkSizeBytes int
}

type Chunk

type Chunk struct {
	ID     string `gorethink:"id,omitempty"`
	FileID string `gorethink:"file_id"`
	Num    int    `gorethink:"num"`
	Data   []byte `gorethink:"data"`
}

type File

type File struct {
	*FileInfo
	// contains filtered or unexported fields
}

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(b []byte) (n int, err error)

func (*File) Write

func (f *File) Write(b []byte) (n int, err error)

type FileInfo

type FileInfo struct {
	ID         string                 `gorethink:"id,omitempty"`
	Filename   string                 `gorethink:"filename"`
	Status     Status                 `gorethink:"status"`
	Length     int                    `gorethink:"length"`
	ChunkSize  int                    `gorethink:"chunkSize"`
	FinishedAt time.Time              `gorethink:"finishedAt"`
	StartedAt  time.Time              `gorethink:"startedAt"`
	DeletedAt  time.Time              `gorethink:"deletedAt"`
	Sha256     string                 `gorethink:"sha256"`
	Metadata   map[string]interface{} `gorethink:"metadata"`
	// contains filtered or unexported fields
}

func (*FileInfo) Open

func (fi *FileInfo) Open() (*File, error)

type FileInfoChange

type FileInfoChange struct {
	NewVal *FileInfo `gorethink:"new_val"`
	OldVal *FileInfo `gorethink:"old_val"`
}

type Status

type Status string
const (
	StatusUnknown    Status = ""
	StatusIncomplete Status = "Incomplete"
	StatusComplete   Status = "Complete"
	StatusDeleted    Status = "Deleted"
)

Jump to

Keyboard shortcuts

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