2014-12-08 22:40:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-12-10 21:54:04 -05:00
|
|
|
"encoding/json"
|
2014-12-08 22:40:48 -05:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/minio-io/minio/pkgs/storage"
|
|
|
|
"github.com/minio-io/minio/pkgs/storage/fsstorage"
|
|
|
|
)
|
|
|
|
|
2014-12-09 06:32:31 -05:00
|
|
|
func fsGetList(config inputConfig) (io.Reader, error) {
|
|
|
|
var objectStorage storage.ObjectStorage
|
|
|
|
rootDir := path.Join(config.rootDir, config.storageDriver)
|
|
|
|
objectStorage = fsstorage.FileSystemStorage{RootDir: rootDir}
|
2014-12-10 21:54:04 -05:00
|
|
|
objectList, err := objectStorage.List("/")
|
2014-12-09 06:32:31 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-12-10 21:54:04 -05:00
|
|
|
var objectListBytes []byte
|
|
|
|
if objectListBytes, err = json.Marshal(objectList); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
objectListBuffer := bytes.NewBuffer(objectListBytes)
|
2014-12-09 06:32:31 -05:00
|
|
|
return objectListBuffer, nil
|
|
|
|
}
|
|
|
|
|
2014-12-08 22:40:48 -05:00
|
|
|
func fsGet(config inputConfig, objectPath string) (io.Reader, error) {
|
|
|
|
var objectStorage storage.ObjectStorage
|
|
|
|
rootDir := path.Join(config.rootDir, config.storageDriver)
|
|
|
|
objectStorage = fsstorage.FileSystemStorage{RootDir: rootDir}
|
|
|
|
object, err := objectStorage.Get(objectPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
objectBuffer := bytes.NewBuffer(object)
|
|
|
|
return objectBuffer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func fsPut(config inputConfig, objectPath string, reader io.Reader) error {
|
|
|
|
var err error
|
|
|
|
rootDir := path.Join(config.rootDir, config.storageDriver)
|
|
|
|
if err := os.MkdirAll(config.rootDir, 0700); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var objectStorage storage.ObjectStorage
|
|
|
|
buffer := new(bytes.Buffer)
|
|
|
|
buffer.ReadFrom(reader)
|
|
|
|
object := buffer.Bytes()
|
|
|
|
objectStorage = fsstorage.FileSystemStorage{RootDir: rootDir}
|
|
|
|
if err = objectStorage.Put(objectPath, object); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|