Documentation ¶
Overview ¶
Package infinite is a Go client for the Infinite database.
Wouldn't it be awesome if you could save the entire Internet into a database? Well, you can now do so! Infinite exploits a simple loophole in your operating system to enable you to store an infinite amount of data, without using a single byte.
How it works ¶
A file contains data, which is measured in bytes. If a file contains 'Hello!', it takes up 7 bytes (remember to count the newline character). If a file contains 'Bye bye~', it takes up 9 bytes. Simple.
Now what if a file contains nothing? How many bytes would the file take up? That's right, 0! But a file can still store data, even if it contains nothing. Where? In its name of course! If we store data in its name, we can now have a file that stores data, but contains nothing, and thus takes up 0 bytes!
Complex documentation ¶
Okay, jokes aside, this project exists simply because I haven't wrote Go in a while. The idea of an infinite database was just a joke I made while half asleep in class.
Example ¶
package main import ( "fmt" "github.com/ravernkoh/infinite" ) func main() { // Load the root node node, err := infinite.Load("db") if err != nil { panic(err) } // Gets the child node child, err := node.Child("user") if err != nil { panic(err) } // Gets the value of the child node user, err := child.Value() if err != nil { panic(err) } fmt.Println(user) }
Output:
Index ¶
- Variables
- type Node
- func (n *Node) Child(key string) (*Node, error)
- func (n *Node) Children() (map[string]*Node, error)
- func (n *Node) Load() error
- func (n *Node) LoadDepth(depth int) error
- func (n *Node) NewChild(key string) (*Node, error)
- func (n *Node) Save() error
- func (n *Node) SetValue(value []byte) error
- func (n *Node) Value() ([]byte, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = fmt.Errorf("infinite: node not found") ErrNotLoaded = fmt.Errorf("infinite: node not loaded") ErrAlreadyExists = fmt.Errorf("infinite: node already exists") ErrInvalidValue = fmt.Errorf("infinite: value is invalid") )
Common errors.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node in the database.
Each node contains a value and some child nodes. Nodes represent a directory in the filesystem, while its value is derived from the names of all the files within it. Any subdirectories would be child nodes.
A node can sometimes be in an unloaded state, which means that its value and its children have not been read from the filesystem. This is desirable in circumstances where the amount of data contained in the child nodes is large and should only be loaded on-demand.
func Load ¶
Load loads a node at the given path from the OS filesystem.
For more details, see LoadVirtualDepth.
func LoadDepth ¶
LoadDepth loads a node at the given path from the OS filesystem, up to the given depth.
For more details, see LoadVirtualDepth.
func LoadVirtual ¶
func LoadVirtual(path string, fs vfs.Filesystem) (*Node, error)
LoadVirtual loads a node at the given path from the given filesystem.
For more details, see LoadVirtualDepth.
func LoadVirtualDepth ¶
LoadVirtualDepth loads a node at the given path from the given filesystem, up to the given depth.
Data contained in the node (including child nodes) is read from the filesystem in a recursive manner, up to the given depth.
func (*Node) Child ¶
Child returns the child node with the corresponding key.
Will fail if the node has not been loaded or if the child cannot be found.
func (*Node) Children ¶
Children returns the children nodes.
Will fail if the node has not been loaded.
func (*Node) LoadDepth ¶
LoadDepth loads the node, up to the given depth.
For more details, see LoadVirtualDepth.
func (*Node) NewChild ¶
NewChild creates a new child node.
Will fail if the node has not been loaded or if the child already exists.
func (*Node) Save ¶
Save saves the node.
All data contained in the node (including child nodes) is written into the filesystem in a recursive manner. Any data that is not defined in the node is removed from the filesystem.