mem

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2020 License: Apache-2.0 Imports: 18 Imported by: 5

README

mem - in memory file storage

This package defines in memory file storage.

Usage
	service := afs.New()
	ctx := context.Background()
	err := service.Upload(ctx, "mem://localhost/folder1/asset.txt", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}
	objects, err := service.List(ctx, "mem://localhost/folder1/")
	if err != nil {
		log.Fatal(err)
	}
	for _, object := range objects {
		fmt.Printf("%v %v\n", object.URL(), object.Name())
	}
    manager := mem.New()
	ctx := context.Background()
	err := manager.Upload(ctx, "mem://localhost/folder1/asset.txt", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}
	objects, err := manager.List(ctx, "mem://localhost/folder1/")
	if err != nil {
		log.Fatal(err)
	}
	for _, object := range objects {
		fmt.Printf("%v %v\n", object.URL(), object.Name())
	}
func main() {
	ctx := context.Background()
    storager := mem.NewStorager("mem://localhost/")
    err := storager.Upload(ctx, "folder1/asset1", 0644, []byte("some content"))
    if err != nil {
        log.Fatal(err)
    }
    err = storager.Upload(ctx, "folder1/asset2", 0644, []byte("some content"))
    if err != nil {
        log.Fatal(err)
    }
    
    fileInfos, err := storager.List(ctx, "folder1/", 0, 0)
    if err != nil {
        log.Fatal(err)
    }
    for _, info := range fileInfos {
        fmt.Printf("%v\n", info.Name())
    }
}
Options

Documentation

Overview

Package mem implements in memory file system

Index

Examples

Constants

View Source
const Scheme = "mem"

Scheme memory URL scheme

Variables

This section is empty.

Functions

func New

func New(options ...storage.Option) storage.Manager

New create a in memory storage

Example
package main

import (
	"context"
	"fmt"
	"github.com/viant/afs/mem"
	"log"
	"strings"
)

func main() {
	manager := mem.New()
	ctx := context.Background()
	err := manager.Upload(ctx, "mem://localhost/folder1/asset.txt", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}
	objects, err := manager.List(ctx, "mem://localhost/folder1/")
	if err != nil {
		log.Fatal(err)
	}
	for _, object := range objects {
		fmt.Printf("%v %v\n", object.URL(), object.Name())
	}
}
Output:

func NewStorager

func NewStorager(baseURL string) storage.Storager

NewStorager create a new in memeory storage service

Example
package main

import (
	"context"
	"fmt"
	"github.com/viant/afs/mem"
	"log"
	"strings"
)

func main() {
	ctx := context.Background()
	storager := mem.NewStorager("mem://localhost/")
	err := storager.Upload(ctx, "folder1/asset1", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}
	err = storager.Upload(ctx, "folder1/asset2", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}

	fileInfos, err := storager.List(ctx, "folder1/", 0, 0)
	if err != nil {
		log.Fatal(err)
	}
	for _, info := range fileInfos {
		fmt.Printf("%v\n", info.Name())
	}

}
Output:

func Provider

func Provider(options ...storage.Option) (storage.Manager, error)

Provider manager provider function

func ResetSingleton

func ResetSingleton(options ...storage.Option)

ResetSingleton rest singleton

func Singleton

func Singleton(options ...storage.Option) storage.Manager

Singleton returns singleton manager

func Split

func Split(URL string) (string, string)

Split split URL with the last URI element and its parent path

func SplitPath

func SplitPath(URLPath string) []string

SplitPath splits path

Types

type File

type File struct {
	storage.Object
	// contains filtered or unexported fields
}

File represents in memory file

func NewFile

func NewFile(URL string, mode os.FileMode, content []byte, modTime time.Time) *File

NewFile create a file

func (*File) NewReader

func (f *File) NewReader() io.ReadCloser

NewReader return new Reader

func (*File) SetErrors

func (f *File) SetErrors(errors ...*option.Error)

SetErrors sets test errors

type Folder

type Folder struct {
	storage.Object
	// contains filtered or unexported fields
}

Folder represents memory folder

func NewFolder

func NewFolder(URL string, mode os.FileMode) *Folder

NewFolder returns a folder for supplied URL

func (*Folder) Delete

func (f *Folder) Delete(name string) error

Delete deletes object or return error

func (*Folder) File

func (f *Folder) File(URL string) (*File, error)

File returns a file for supplied location

func (*Folder) Folder

func (f *Folder) Folder(URL string, mkdirMode os.FileMode) (*Folder, error)

Folder returns a folder for supplied URL, when mkdirMode is non zero it will create missing folders with supplied mode

func (*Folder) Lookup

func (f *Folder) Lookup(URL string, mkdirMode os.FileMode) (storage.Object, error)

Lookup lookup path, when mkdirMode is non zero it will create missing folders with supplied mode

func (*Folder) Objects

func (f *Folder) Objects() []storage.Object

Objects returns folder objects

func (*Folder) Put

func (f *Folder) Put(object storage.Object) error

Put adds object to this folder

Jump to

Keyboard shortcuts

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