infinite

package module
v0.0.0-...-18ee394 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

README

Infinite

GoDoc GoReportCard TravisCI

The database that can store the Internet.

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!

Here, have some evidence.

Evidence

Installation

Infinite is available as a binary and also as a Go package.

Binary

If Go is installed, the following command can be run to install the binary.

$ vgo get github.com/ravernkoh/infinite/...

Otherwise, the binary for each platform can be downloaded from the releases page.

Package

Use vgo to download the package.

$ vgo get github.com/ravernkoh/infinite

Usage

The binary can be used to explore existing Infinite nodes or create new ones.

# Create root node called db
$ mkdir db

# Set the value to "value"
$ infinite value db --set value

# Create a child node called "child"
$ infinite children db --new child

# Print the value of the node
$ infinite value db
value

# Print the list of child nodes
$ infinite children db
child

Examples for the package can be found in the documentation.

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.

License

This project is licensed under the GNU Public License 3.0.

Author

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

Examples

Constants

This section is empty.

Variables

View Source
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

func Load(path string) (*Node, error)

Load loads a node at the given path from the OS filesystem.

For more details, see LoadVirtualDepth.

func LoadDepth

func LoadDepth(path string, depth int) (*Node, error)

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

func LoadVirtualDepth(path string, fs vfs.Filesystem, depth int) (*Node, error)

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

func (n *Node) Child(key string) (*Node, error)

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

func (n *Node) Children() (map[string]*Node, error)

Children returns the children nodes.

Will fail if the node has not been loaded.

func (*Node) Load

func (n *Node) Load() error

Load loads the node.

For more details, see LoadVirtualDepth.

func (*Node) LoadDepth

func (n *Node) LoadDepth(depth int) error

LoadDepth loads the node, up to the given depth.

For more details, see LoadVirtualDepth.

func (*Node) NewChild

func (n *Node) NewChild(key string) (*Node, error)

NewChild creates a new child node.

Will fail if the node has not been loaded or if the child already exists.

func (*Node) Save

func (n *Node) Save() error

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.

func (*Node) SetValue

func (n *Node) SetValue(value []byte) error

SetValue sets the value of the node.

Will fail if the node has not been loaded.

func (*Node) Value

func (n *Node) Value() ([]byte, error)

Value returns the value of the node.

Will fail if the node has not been loaded.

Directories

Path Synopsis
cmd
infinite
Command infinite is a command-line client for the Infinite database.
Command infinite is a command-line client for the Infinite database.

Jump to

Keyboard shortcuts

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