2014-10-22 00:02:20 +02:00
|
|
|
package storagedriver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// StorageDriver defines methods that a Storage Driver must implement for a filesystem-like
|
|
|
|
// key/value object storage
|
2014-10-22 00:02:20 +02:00
|
|
|
type StorageDriver interface {
|
2014-10-29 20:14:19 +01:00
|
|
|
// GetContent retrieves the content stored at "path" as a []byte
|
2014-10-29 02:15:40 +01:00
|
|
|
// Should primarily be used for small objects
|
2014-10-22 00:02:20 +02:00
|
|
|
GetContent(path string) ([]byte, error)
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// PutContent stores the []byte content at a location designated by "path"
|
2014-10-29 02:15:40 +01:00
|
|
|
// Should primarily be used for small objects
|
2014-10-22 00:02:20 +02:00
|
|
|
PutContent(path string, content []byte) error
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a given byte
|
|
|
|
// offset
|
2014-10-29 02:15:40 +01:00
|
|
|
// May be used to resume reading a stream by providing a nonzero offset
|
2014-10-22 00:02:20 +02:00
|
|
|
ReadStream(path string, offset uint64) (io.ReadCloser, error)
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// WriteStream stores the contents of the provided io.ReadCloser at a location designated by
|
|
|
|
// the given path
|
2014-10-29 02:15:40 +01:00
|
|
|
// The driver will know it has received the full contents when it has read "size" bytes
|
|
|
|
// May be used to resume writing a stream by providing a nonzero offset
|
|
|
|
// The offset must be no larger than the number of bytes already written to this path
|
2014-10-22 00:02:20 +02:00
|
|
|
WriteStream(path string, offset, size uint64, readCloser io.ReadCloser) error
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// ResumeWritePosition retrieves the byte offset at which it is safe to continue writing at the
|
|
|
|
// given path
|
2014-10-22 00:02:20 +02:00
|
|
|
ResumeWritePosition(path string) (uint64, error)
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// List recursively lists the objects stored at a subpath of the given prefix
|
2014-10-22 00:02:20 +02:00
|
|
|
List(prefix string) ([]string, error)
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// Move moves an object stored at sourcePath to destPath, removing the original object
|
2014-10-29 02:15:40 +01:00
|
|
|
// Note: This may be no more efficient than a copy followed by a delete for many implementations
|
2014-10-22 00:02:20 +02:00
|
|
|
Move(sourcePath string, destPath string) error
|
2014-10-29 02:15:40 +01:00
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// Delete recursively deletes all objects stored at "path" and its subpaths
|
2014-10-22 00:02:20 +02:00
|
|
|
Delete(path string) error
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// PathNotFoundError is returned when operating on a nonexistent path
|
2014-10-22 00:02:20 +02:00
|
|
|
type PathNotFoundError struct {
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err PathNotFoundError) Error() string {
|
|
|
|
return fmt.Sprintf("Path not found: %s", err.Path)
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:14:19 +01:00
|
|
|
// InvalidOffsetError is returned when attempting to read or write from an invalid offset
|
2014-10-22 00:02:20 +02:00
|
|
|
type InvalidOffsetError struct {
|
|
|
|
Path string
|
|
|
|
Offset uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err InvalidOffsetError) Error() string {
|
|
|
|
return fmt.Sprintf("Invalid offset: %d for path: %s", err.Offset, err.Path)
|
|
|
|
}
|