unionfs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

UnionFS

CI PkgGoDev GoReportCard Coverage

UnionFS for Golang io/fs.FS

LICENSE

Copyright 2021 The arhat.dev Authors.

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.

Documentation

Overview

Package unionfs provides unification of multiple io/fs.FS

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathKeyFunc

func PathKeyFunc(key string, pos int) (string, int)

Types

type UnionFS

type UnionFS struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"embed"
	"io"
	"io/fs"
	"os"
	"strconv"

	"arhat.dev/unionfs"
)

var (
	//go:embed trie
	sampleEmbedFS embed.FS

	sampleOSFS = os.DirFS("/some/rootfs")
)

func main() {
	ufs := unionfs.New()
	ufs.Map("/go/arhat.dev/unionfs/trie", "trie", sampleEmbedFS)
	ufs.Map("/", "/some/rootfs", sampleOSFS)

	f, err := ufs.Open("/go/arhat.dev/unionfs/trie/trie.go")
	if err != nil {
		panic(err)
	}
	defer func() { _ = f.Close() }()

	info, err := f.Stat()
	if err != nil {
		return
	}
	println("FILE trie.go NAME:", info.Name())

	_, _ = io.ReadAll(f)

	entries, err := fs.ReadDir(ufs, "/go/arhat.dev/unionfs/trie")
	if err != nil {
		panic(err)
	}

	for i, ent := range entries {
		println("DIR trie/#"+strconv.Itoa(i)+" NAME:", ent.Name())
	}
}
Output:

func New

func New() *UnionFS

func (*UnionFS) Map

func (ufs *UnionFS) Map(newPrefix, oldPrefix string, vfs fs.FS)

Map existing vfs with new path prefix inside the ufs, old prefix is required to access actual vfs data

func (*UnionFS) Open

func (ufs *UnionFS) Open(name string) (fs.File, error)

func (*UnionFS) ReadDir

func (ufs *UnionFS) ReadDir(name string) ([]fs.DirEntry, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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