storage

package
v0.0.0-...-88c3b2e Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2012 Sergey Cherepanov (https://github.com/cheggaaa)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ALLOC_REPLACE = 1
	ALLOC_APPEND  = 2
	ALLOC_INSERT  = 3
)
View Source
const WILDCARD = "*"

Variables

View Source
var (
	ErrConflict = errors.New("Conflict")
)
View Source
var ErrFileExists = errors.New("File exists")
View Source
var ErrFileNotFound = errors.New("File not found")
View Source
var R = Rounder{}

Functions

This section is empty.

Types

type CType

type CType string

func (*CType) String

func (ct *CType) String() string

type Container

type Container struct {
	Id                  int64
	Created             bool
	Size                int64
	FileCount, FileSize int64
	FileRealSize        int64
	FDump               map[int64]*File
	HDump               map[int64]*Hole
	// contains filtered or unexported fields
}

func (*Container) Allocate

func (c *Container) Allocate(f *File, target int) (ok bool)

func (*Container) Check

func (c *Container) Check() (err error)

func (*Container) Close

func (c *Container) Close() (err error)

func (*Container) Delete

func (c *Container) Delete(f *File)

func (*Container) Dump

func (c *Container) Dump() (err error)

func (*Container) Init

func (c *Container) Init(s *Storage) (err error)

func (*Container) Print

func (c *Container) Print()

type File

type File struct {
	Hole  // inherits
	Name  string
	Md5   []byte
	FSize int64
	Time  time.Time
	// contains filtered or unexported fields
}

func (*File) CheckMd5

func (f *File) CheckMd5() (err error)

func (*File) Close

func (f *File) Close()

need call after open

func (*File) ContentType

func (f *File) ContentType() (ctype string)

Return content type file or application/octed-stream if can't

func (*File) Delete

func (f *File) Delete()

mark as deleted

func (*File) ETag

func (f *File) ETag() string

return http E-Tag

func (*File) GetReader

func (f *File) GetReader() *Reader

return io.Reader

func (*File) Init

func (f *File) Init(c *Container)

func (*File) IsFree

func (f *File) IsFree() bool

implement Space interafce

func (*File) Md5S

func (f *File) Md5S() string

string md5

func (*File) Open

func (f *File) Open() (err error)

mark file as Open

func (*File) ReadFrom

func (f *File) ReadFrom(r io.Reader) (written int64, err error)

copy content from io.Reader

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (int, error)

type Hole

type Hole struct {

	// Offset
	Off int64
	// Index
	Indx int
	// contains filtered or unexported fields
}

func (*Hole) End

func (h *Hole) End() int64

func (*Hole) Index

func (h *Hole) Index() int

func (*Hole) IsFree

func (h *Hole) IsFree() bool

func (*Hole) Next

func (h *Hole) Next() Space

implement Space

func (*Hole) Offset

func (h *Hole) Offset() int64

func (*Hole) Prev

func (h *Hole) Prev() Space

func (*Hole) SetNext

func (h *Hole) SetNext(s Space)

func (*Hole) SetOffset

func (h *Hole) SetOffset(o int64)

func (*Hole) SetPrev

func (h *Hole) SetPrev(s Space)

func (*Hole) Size

func (h *Hole) Size() int64

type HoleIndex

type HoleIndex struct {
	Count int64
	Size  int64
	// contains filtered or unexported fields
}

func (*HoleIndex) Add

func (hi *HoleIndex) Add(holes ...*Hole)

func (*HoleIndex) Create

func (hi *HoleIndex) Create(prev, next Space, offset int64, index int) (h *Hole)

func (*HoleIndex) Delete

func (hi *HoleIndex) Delete(s *Hole)

func (*HoleIndex) Exists

func (hi *HoleIndex) Exists(h *Hole) bool

func (*HoleIndex) Get

func (hi *HoleIndex) Get(index int) *Hole

func (*HoleIndex) GetBiggest

func (hi *HoleIndex) GetBiggest(index int) *Hole

func (*HoleIndex) Init

func (hi *HoleIndex) Init()

func (*HoleIndex) Print

func (hi *HoleIndex) Print()

type Index

type Index struct {
	Root *Node
	// contains filtered or unexported fields
}

func (*Index) Add

func (i *Index) Add(file *File) (err error)

Add new file to index

func (*Index) Count

func (i *Index) Count() int64

func (*Index) Delete

func (i *Index) Delete(name string) (f *File, ok bool)

func (*Index) Get

func (i *Index) Get(name string) (f *File, ok bool)

func (*Index) Init

func (i *Index) Init()

func (*Index) List

func (i *Index) List(prefix string, maxnesting int) (names []string, err error)

func (*Index) Rename

func (i *Index) Rename(name, newName string) (f *File, err error)

func (*Index) Version

func (i *Index) Version() int64

type Node

type Node struct {
	File   *File
	Childs map[string]*Node
}

func (*Node) Add

func (n *Node) Add(parts []string, f *File, depth int) (err error)

func (*Node) Delete

func (n *Node) Delete(parts []string, depth int) (f *File, err error)

func (*Node) Get

func (n *Node) Get(parts []string, depth int) (f *File, err error)

func (*Node) IsFile

func (n *Node) IsFile() bool

func (*Node) List

func (n *Node) List(parts []string, depth, nesting int) (files []string, err error)

func (*Node) Print

func (n *Node) Print(prefix string)

type Reader

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

func (*Reader) Read

func (s *Reader) Read(p []byte) (n int, err error)

func (*Reader) ReadAt

func (s *Reader) ReadAt(p []byte, off int64) (n int, err error)

func (*Reader) Seek

func (s *Reader) Seek(offset int64, whence int) (ret int64, err error)

func (*Reader) Size

func (s *Reader) Size() int64

func (*Reader) WriteTo

func (s *Reader) WriteTo(dst io.Writer) (written int64, err error)

type Rounder

type Rounder struct{}

func (Rounder) Index

func (r Rounder) Index(size int64) int

*

  • 2,4,8,16..512,1024 - n2
  • 1k,2k,3k...15k,16k - 1k
  • 16k,32k,48k..112k,128k - 16k
  • 128k,256k,384k..3968k,4096k - 128k
  • 4m,5m,6m... - 1mb *

func (Rounder) Round

func (r Rounder) Round(size int64) int64

func (Rounder) Size

func (r Rounder) Size(index int) int64

type Space

type Space interface {
	SetNext(Space)
	SetPrev(Space)
	Next() Space
	Prev() Space
	SetOffset(int64)
	Offset() int64
	Size() int64
	Index() int
	End() int64
	IsFree() bool
}

type Storage

type Storage struct {
	Conf            *config.Config
	Index           *Index
	LastContainerId int64
	Stats           *stats.Stats
	Containers      map[int64]*Container
	// contains filtered or unexported fields
}

func (*Storage) Add

func (s *Storage) Add(name string, r io.Reader, size int64) (f *File, err error)

func (*Storage) Check

func (s *Storage) Check() (err error)

func (*Storage) Close

func (s *Storage) Close()

func (*Storage) Delete

func (s *Storage) Delete(name string) (ok bool)

func (*Storage) DeleteChilds

func (s *Storage) DeleteChilds(name string) (ok bool)

func (*Storage) Drop

func (s *Storage) Drop()

func (*Storage) Dump

func (s *Storage) Dump()

func (*Storage) Get

func (s *Storage) Get(name string) (f *File, ok bool)

func (*Storage) GetStats

func (s *Storage) GetStats() *stats.Stats

func (*Storage) Init

func (s *Storage) Init(c *config.Config)

func (*Storage) Open

func (s *Storage) Open() (err error)

Jump to

Keyboard shortcuts

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