memfs

package
v0.0.0-...-7b20d7d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"io/fs"

	"github.com/halimath/fsx"
	"github.com/halimath/fsx/memfs"
)

func main() {
	// Create a fsx.FS using the temp dir.
	fsys := memfs.New()

	// Create a file inside the fsys.
	f, err := fsx.Create(fsys, "test.md")
	if err != nil {
		panic(err)
	}

	// Write some content to the file.
	if _, err := f.Write([]byte("# fsx example test\n\nThis is just an example.")); err != nil {
		panic(err)
	}

	if err := f.Close(); err != nil {
		panic(err)
	}

	// Create a symlink inside the fsys
	if err := fsys.Symlink("test.md", "README.md"); err != nil {
		panic(err)
	}

	// Now try to read the symlinked file using fs.ReadFile
	content, err := fs.ReadFile(fsys, "README.md")
	if err != nil {
		panic(err)
	}

	fmt.Println(string(content))
}
Output:

# fsx example test

This is just an example.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrIsDirectory = errors.New("is a directory")

Functions

func New

func New() fsx.LinkFS

New creates a new, empty in-memory filesystem.

Types

type Stat

type Stat struct {
	// The owners UID.
	Uid int
	// The owners GID.
	Gid int
	// The time the element was last accessed
	Atime time.Time
	// The time the element was last modified. This is identical to the value
	// returned from fs.FileInfo.ModTime().
	Mtime time.Time
}

Stat defines a structure that is returned from calls to fs.FileInfo.Sys() for all elements contained in a memfs.

Jump to

Keyboard shortcuts

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