Esempio n. 1
0
package otaru

import (
	"fmt"

	"github.com/nyaxt/otaru/chunkstore"
	"github.com/nyaxt/otaru/inodedb"
)

type INodeDBChunksArrayIO struct {
	db    inodedb.DBHandler
	nlock inodedb.NodeLock
}

var _ = chunkstore.ChunksArrayIO(&INodeDBChunksArrayIO{})

func NewINodeDBChunksArrayIO(db inodedb.DBHandler, nlock inodedb.NodeLock) *INodeDBChunksArrayIO {
	return &INodeDBChunksArrayIO{db: db, nlock: nlock}
}

func (caio *INodeDBChunksArrayIO) Read() ([]inodedb.FileChunk, error) {
	v, _, err := caio.db.QueryNode(caio.nlock.ID, false)
	if err != nil {
		return nil, err
	}

	fn, ok := v.(*inodedb.FileNodeView)
	if !ok {
		return nil, fmt.Errorf("Target node view is not a file.")
	}
Esempio n. 2
0
	"github.com/nyaxt/otaru/btncrypt"
	"github.com/nyaxt/otaru/chunkstore"
	"github.com/nyaxt/otaru/inodedb"
	. "github.com/nyaxt/otaru/testutils"

	"bytes"
	"fmt"
	"reflect"
	"testing"
)

type SimpleDBChunksArrayIO struct {
	cs []inodedb.FileChunk
}

var _ = chunkstore.ChunksArrayIO(&SimpleDBChunksArrayIO{})

func NewSimpleDBChunksArrayIO() *SimpleDBChunksArrayIO {
	return &SimpleDBChunksArrayIO{make([]inodedb.FileChunk, 0)}
}

func (caio *SimpleDBChunksArrayIO) Read() ([]inodedb.FileChunk, error) {
	return caio.cs, nil
}

func (caio *SimpleDBChunksArrayIO) Write(cs []inodedb.FileChunk) error {
	caio.cs = cs
	return nil
}

func (caio *SimpleDBChunksArrayIO) Close() error { return nil }