filesystem

package
v0.0.0-...-48c028d Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 12 Imported by: 0

README

FileSystem

FileSystem provides a simple API to create an in-memory file system with internal directories and files, represented by a composition of functions.

API

To create an in-memory file system with simple function composition.

dockerFS = FileSystem(
  Meta("version", "1.0"),
  Description("FileSystem for the faas docker system"),
  Dir("app"),
  File(

  ),
  File(
    "dockerfile",
    Content(`
      FROM alpine:latest

      RUN sudo apt-get update
      RUN sudo apt-get install git golang

      CMD ["/bin/bomb"]
    `)
  ),
)

var dest io.Writer

gzipDockerFS = GZipTarFS(dockerFS)
gzipDockerFS.WriteTo(dest)

tarDockerFS = TarFS(dockerFS)
tarDockerFS.WriteTo(dest)

zipDockerFS = ZipFS(dockerFS)
zipDockerFS.WriteTo(dest)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Content

func Content(data string) io.WriterTo

Content returns a io.WriterTo containing the provided data string.

func ContentByte

func ContentByte(data []byte) io.WriterTo

ContentByte returns a io.WriterTo containing the provided data bytes.

func ContentFrom

func ContentFrom(r io.Reader) io.WriterTo

ContentFrom returns a io.WriterTo which wraps the io.Reader for piping the data from the giving reader.

Types

type DirWriter

type DirWriter struct {
	Name       string
	ChildFiles []FileWriter
	ChildDirs  []DirWriter
}

DirWriter implements a structure that represents a file system directory with associated files and name.

func Dir

func Dir(name string, files ...interface{}) DirWriter

Dir returns a instance of a DirWriter with associated name. The files are scanned and are appropriately allocated if they are FileWriter or DirWriter.

func (DirWriter) Dirs

func (dirs DirWriter) Dirs(rootDir string, cb func(hostDirPath string, hostDir DirWriter) error) error

Dirs runs through all child directory returning appropriate path and current item associated for that DirWriter.

func (DirWriter) Files

func (dirs DirWriter) Files(rootDir string, cb func(hostFilePath string, hostFile FileWriter) error) error

Files runs through all child directory returning appropriate path and current item associated for that DirWriter.

func (DirWriter) GetDir

func (dirs DirWriter) GetDir(dirPath string) (DirWriter, error)

GetDir returns the associated DirWriter for the giving relative filepath. Absolute path will be rejected.

func (DirWriter) GetFile

func (dirs DirWriter) GetFile(filePath string) (FileWriter, error)

GetFile returns the associated FileWriter for the giving relative filepath. Absolute path will be rejected.

type FileWriter

type FileWriter struct {
	Name    string
	Content io.WriterTo
}

FileWriter defines a structure that represent a file system file item with associated content.

func File

func File(name string, content io.WriterTo) FileWriter

File returns a instance of a FileWriter with associated name and content.

type Filesystem

type Filesystem interface {
	io.WriterTo
	ToReader() (io.Reader, error)
}

Filesystem defines a interface which expose a an underline compressed/uncompressed filesystem which can be written out into a writer or produce a reader for reading has a single binary stream of bytes.

type GzipTarFileSystem

type GzipTarFileSystem struct {
	FS MemoryFileSystem
}

GzipTarFileSystem implements io.WriteTo and transforms the MemoryFileSystem into a tar archive using the archive/tar writer to wrap a compress/gzip writer.

func GzipTarFS

func GzipTarFS(fs MemoryFileSystem) GzipTarFileSystem

GzipTarFS returns a new instance of the GzipTarFileSystem.

func (GzipTarFileSystem) ToReader

func (gfs GzipTarFileSystem) ToReader() (io.Reader, error)

ToReader returns a new reader from the contents of the GzipTarFileSystem. Each reader is unique and contains a complete data of all contents.

func (GzipTarFileSystem) WriteTo

func (gfs GzipTarFileSystem) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface.

type JSONFileSystem

type JSONFileSystem struct {
	FS MemoryFileSystem
	// contains filtered or unexported fields
}

JSONFileSystem implements io.WriteTo and transforms the MemoryFileSystem into a json hashmap using the encoding/json encoders.

func JSONFS

func JSONFS(fs MemoryFileSystem, indent bool) JSONFileSystem

JSONFS returns a new instance of the JSONFileSystem.

func (JSONFileSystem) ToReader

func (jfs JSONFileSystem) ToReader() (io.Reader, error)

ToReader returns a new reader from the contents of the GzipTarFileSystem. Each reader is unique and contains a complete data of all contents.

func (JSONFileSystem) WriteTo

func (jfs JSONFileSystem) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface.

type MemoryFileSystem

type MemoryFileSystem struct {
	Dir  DirWriter
	Meta map[string]interface{}
}

MemoryFileSystem defines a file system with associated files and directories which are to be converted into appropriate data stream by a consumer.

func FileSystem

func FileSystem(content ...interface{}) MemoryFileSystem

FileSystem returns a instance of a FSWriter.

func (MemoryFileSystem) Dirs

func (mfs MemoryFileSystem) Dirs(cb func(hostFilePath string, hostFile DirWriter) error) error

Dirs runs through all filesystem child directories returning appropriate path and file to the provided callback.

func (MemoryFileSystem) Files

func (mfs MemoryFileSystem) Files(cb func(hostFilePath string, hostFile FileWriter) error) error

Files runs through all filesystem files and child directory files returning appropriate path and file to the provided callback.

func (MemoryFileSystem) GetDir

func (mfs MemoryFileSystem) GetDir(dirPath string) (DirWriter, error)

GetDir returns the associated FileWriter for the giving relative filepath. Absolute path will be rejected.

func (MemoryFileSystem) GetFile

func (mfs MemoryFileSystem) GetFile(filePath string) (FileWriter, error)

GetFile returns the associated FileWriter for the giving relative filepath. Absolute path will be rejected.

type MetaOption

type MetaOption func(map[string]interface{})

MetaOption defines a function which receives a map to set values as desired.

func Description

func Description(desc string, items ...interface{}) MetaOption

Description sets the "description" key to the provided string in a map.

func Meta

func Meta(name string, val interface{}) MetaOption

Meta sets the key(name) to the val in a map.

func MetaApply

func MetaApply(ops ...MetaOption) MetaOption

MetaApply returns a MetaOption that applies a series of provided options to a map.

func MetaText

func MetaText(name string, message string, vals ...interface{}) MetaOption

MetaText sets the key(name) to the val in a map.

func Version

func Version(ver string) MetaOption

Version sets the "version" key to the provided string in a map.

type TarFileSystem

type TarFileSystem struct {
	FS MemoryFileSystem
}

TarFileSystem implements io.WriteTo and transforms the MemoryFileSystem into a tar archive using the archive/tar writers.

func TarFS

TarFS returns a new instance of the TarFileSystem.

func (TarFileSystem) ToReader

func (tfs TarFileSystem) ToReader() (io.Reader, error)

ToReader returns a new reader from the contents of the GzipTarFileSystem. Each reader is unique and contains a complete data of all contents.

func (TarFileSystem) WriteTo

func (tfs TarFileSystem) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface.

type ZipFileSystem

type ZipFileSystem struct {
	FS MemoryFileSystem
}

ZipFileSystem implements io.WriteTo and transforms the MemoryFileSystem into a tar archive using the archive/zip writers.

func ZipFS

ZipFS returns a new instance of the ZipFileSystem.

func (ZipFileSystem) ToReader

func (zfs ZipFileSystem) ToReader() (io.Reader, error)

ToReader returns a new reader from the contents of the GzipTarFileSystem. Each reader is unique and contains a complete data of all contents.

func (ZipFileSystem) WriteTo

func (zfs ZipFileSystem) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface.

Directories

Path Synopsis
Package osconv defines a function which runs through a giving directory and returns a Filesystem in return.
Package osconv defines a function which runs through a giving directory and returns a Filesystem in return.

Jump to

Keyboard shortcuts

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