Skip to content

Simple filesystem implementation that represents all the paths as a trie.

License

Notifications You must be signed in to change notification settings

kalambet/trie-fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trie-fs

A Go library that implements an in-memory trie-based file system. It stores files and directories in a compressed trie structure, providing path-based operations like listing, lookup, and deletion. The trie is safe for concurrent use.

Install

go get github.com/kalambet/trie-fs

Usage

package main

import (
	"fmt"
	"time"

	triefs "github.com/kalambet/trie-fs"
)

func main() {
	// Create a new trie.
	t := triefs.NewTrie()

	// Add files.
	now := time.Now()
	t.AddFile(triefs.NewEntry("/docs/readme.txt", "cid1", 128, triefs.MIMEOctetStream, now))
	t.AddFile(triefs.NewEntry("/docs/notes.txt", "cid2", 64, triefs.MIMEOctetStream, now))

	// List a directory.
	for _, c := range t.Ls("/docs") {
		fmt.Println(c.Name, c.Type)
	}

	// Look up a single file.
	content, err := t.File("/docs/readme.txt")
	if err != nil {
		panic(err)
	}
	fmt.Println(content.Name, content.Size)

	// Delete a file.
	t.Delete("/docs/notes.txt")
}

License

MIT

About

Simple filesystem implementation that represents all the paths as a trie.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages