sectionedfs

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 9 Imported by: 1

README

Sectioned Fs

Go Reference pipeline status coverage report goreport

This package implements an afero.Fs with directories at the root mapped by strings to other afero.Fs's.

The interface adds two

package sectionedfs_test

import (
	"fmt"
	"io/ioutil"

	"github.com/spf13/afero"
	"gitlab.com/tbhartman/sectionedfs"
)

func ExampleFs() {
    a := afero.NewMemMapFs()
    b := afero.NewMemMapFs()

    parentFs := sectionedfs.New()
    parentFs.RegisterSection("a", a)
    parentFs.RegisterSection("b", b)

    fs := parentFs.(afero.Fs)
    fs.MkdirAll("/a/dir_under_a", 0700)
    fs.MkdirAll("/b/dir_under_b", 0700)

    fa, _ := fs.Create("/a/dir_under_a/file_in_a")
    fa.WriteString("sample text\n")
    fa.Close()

    fileViaChild, _ := a.Open("/dir_under_a/file_in_a")
    contents, _ := ioutil.ReadAll(fileViaChild)
    fmt.Print(string(contents))
    // Output: sample text
}

Documentation

Overview

Package sectionedfs implements an afero.Fs filesystem in which immediate subdirectories are named by strings mapped to other afero.Fs filesystems. You can combine disparate directories from multiple filesystems into what is accessed as a single directory.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fs

type Fs interface {
	afero.Fs
	RegisterSection(name string, sec afero.Fs) error
}

Fs implements the afero.Fs interface for a group of named afero.Fs's. Each sub-Fs is accessed via the first element of the paths given to Fs

Example
package main

import (
	"fmt"
	"io/ioutil"

	"github.com/spf13/afero"
	"gitlab.com/tbhartman/sectionedfs"
)

func main() {
	a := afero.NewMemMapFs()
	b := afero.NewMemMapFs()

	parentFs := sectionedfs.New()
	parentFs.RegisterSection("a", a)
	parentFs.RegisterSection("b", b)

	fs := parentFs.(afero.Fs)
	fs.MkdirAll("a/dir_under_a", 0700)
	fs.MkdirAll("b/dir_under_b", 0700)

	fa, _ := fs.Create("a/dir_under_a/file_in_a")
	fa.WriteString("sample text\n")
	fa.Close()

	fileViaChild, _ := a.Open("dir_under_a/file_in_a")
	contents, _ := ioutil.ReadAll(fileViaChild)
	fmt.Print(string(contents))
}
Output:

sample text

func New

func New() Fs

New creates a new SectionedFs

Jump to

Keyboard shortcuts

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