mapfs

package module
v0.0.0-...-b06f77e Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2017 License: MIT Imports: 8 Imported by: 0

README

go-mapfs

Build Status Go Report Card Coverage Status GoDoc

A map-based vfs.FileSystem implementation that stores both the contents and the modification times for files.

Usage

Each input file is represented by the File structure that stores the contents and the modification time of the file.

type File struct {
  Data    []byte
  ModTime time.Time
}

These Files are collected in a Files map that maps each file to the file's path.

type Files map[string]*File

The New function creates the file system from the map.

func New(Files) (vfs.FileSystem, error)
Example
package main

import (
  "time"

  "github.com/ZoltanLajosKis/go-mapfs"
)

func main() {
  files := mapfs.Files{
    "test/hello.txt": {
      []byte("Hello."),
      time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC),
    },
    // additional files ...
  }

  fs, err := mapfs.New(files)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(files Files) (vfs.FileSystem, error)

New creates a new MapFS instance from the input files.

Types

type File

type File struct {
	Data    []byte
	ModTime time.Time
}

File represents a file's contents and modification time.

type Files

type Files map[string]*File

Files is the collection of files to init a MapFS file system with. It maps the file's full path to its File descriptor. The map only contains files, directories will be created implicitly.

type MapFS

type MapFS map[string]*fsEntry

MapFS is a vfs.FileSystem implementation.

func (MapFS) Lstat

func (fs MapFS) Lstat(p string) (os.FileInfo, error)

Lstat returns the fileinfo of a file or link.

func (MapFS) Open

func (fs MapFS) Open(p string) (vfs.ReadSeekCloser, error)

Open implements vfs.Opener.

func (MapFS) ReadDir

func (fs MapFS) ReadDir(p string) ([]os.FileInfo, error)

ReadDir reads the directory named by path and returns a list of sorted directory entries.

func (MapFS) Stat

func (fs MapFS) Stat(p string) (os.FileInfo, error)

Stat returns the fileinfo of a file.

func (MapFS) String

func (fs MapFS) String() string

Jump to

Keyboard shortcuts

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