• Stars
    star
    465
  • Rank 94,287 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Virtual filesystem library written in golang

vfs for golang Build Status GoDoc Coverage Status Join the chat at https://gitter.im/blang/vfs

vfs is library to support virtual filesystems. It provides basic abstractions of filesystems and implementations, like OS accessing the file system of the underlying OS and memfs a full filesystem in-memory.

Usage

$ go get github.com/blang/vfs

Note: Always vendor your dependencies or fix on a specific version tag.

import github.com/blang/vfs
// Create a vfs accessing the filesystem of the underlying OS
var osfs vfs.Filesystem = vfs.OS()
osfs.Mkdir("/tmp", 0777)

// Make the filesystem read-only:
osfs = vfs.ReadOnly(osfs) // Simply wrap filesystems to change its behaviour

// os.O_CREATE will fail and return vfs.ErrReadOnly
// os.O_RDWR is supported but Write(..) on the file is disabled
f, _ := osfs.OpenFile("/tmp/example.txt", os.O_RDWR, 0)

// Return vfs.ErrReadOnly
_, err := f.Write([]byte("Write on readonly fs?"))
if err != nil {
    fmt.Errorf("Filesystem is read only!\n")
}

// Create a fully writable filesystem in memory
mfs := memfs.Create()
mfs.Mkdir("/root", 0777)

// Create a vfs supporting mounts
// The root fs is accessing the filesystem of the underlying OS
fs := mountfs.Create(osfs)

// Mount a memfs inside /memfs
// /memfs may not exist
fs.Mount(mfs, "/memfs")

// This will create /testdir inside the memfs
fs.Mkdir("/memfs/testdir", 0777)

// This would create /tmp/testdir inside your OS fs
// But the rootfs `osfs` is read-only
fs.Mkdir("/tmp/testdir", 0777)

Check detailed examples below. Also check the GoDocs.

Why should I use this lib?

  • Only Stdlib
  • (Nearly) Fully tested (Coverage >90%)
  • Easy to create your own filesystem
  • Mock a full filesystem for testing (or use included memfs)
  • Compose/Wrap Filesystems ReadOnly(OS()) and write simple Wrappers
  • Many features, see GoDocs and examples below

Features and Examples

Current state: ALPHA

While the functionality is quite stable and heavily tested, interfaces are subject to change.

You need more/less abstraction? Let me know by creating a Issue, thank you.

Motivation

I simply couldn't find any lib supporting this wide range of variation and adaptability.

Contribution

Feel free to make a pull request. For bigger changes create a issue first to discuss about it.

License

See LICENSE file.

More Repositories

1

semver

Semantic Versioning (semver) library written in golang
Go
1,007
star
2

latex-docker

Docker-based latex compilation
Makefile
583
star
3

mpv

mpv remote control library written in golang
Go
37
star
4

golang-alpine-docker

Build golang binaries for alpine linux
Makefile
36
star
5

thymer

Console Pomodoro Timer written in golang
Go
18
star
6

expenv

Expands environment variables in config files
Go
13
star
7

ghkeys

Utility to get github user keys
Go
12
star
8

gluster-server

GlusterFS server docker container
12
star
9

methodr

HTTP Method based Router written in golang
Go
9
star
10

expenv.sh

Expands files with environment variables (shell script)
Shell
5
star
11

speedtest

Simple TCP Speedtest written in golang
Go
4
star
12

e12bot

Go
3
star
13

whoshome

Who's home tracks presence
Go
2
star
14

photowall

Photowall written in golang
JavaScript
2
star
15

studip

StudIP API library written in golang (adjusted for University Passau)
Go
2
star
16

imgserv

Simple image upload and serving
Go
2
star
17

btrfs-initrd

Initrd creation to support boot from btrfs subvolume
Shell
1
star
18

hornet-webfrontend

JavaScript
1
star
19

rfm69-gateway

Go
1
star
20

CppTutorialUniPassau

Cpp Tutorial Sources
C++
1
star
21

sexec

Simple command execution for golang
Go
1
star
22

stinger

Go
1
star
23

receptor

Go
1
star
24

wasp

File repository written in golang
Go
1
star
25

hornet

Go
1
star
26

gosqm

SQM Format Toolchain written in golang
Go
1
star
27

transmerge

Merges 2 yaml translation files
Ruby
1
star
28

quiddle.js

Simple embeddable HTML, CSS, JS Playground
JavaScript
1
star
29

mcu-tempmonitor

NodeMCU Temperature sensor with golang backend and http frontend
Lua
1
star
30

crane

WIP! Docker Repository
Go
1
star
31

k8split

Go
1
star
32

late

Free templating utility
Go
1
star