files

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package files is a layer over a normal directory to synthesize Stat responses, and allow special semantics for Read/Write requests to opened files

Adding

import (
	"os"
	"path"

	"github.com/altid/server/files"
)

type NormalHandler struct{}

func NewNormal() *NormalHandler { return &NormalHandler{} }

func (*NormalHandler) Normal(msg *files.Message) (interface{}, error) {
	fp := path.Join(msg.Service, msg.Buffer, msg.Target)
	return os.Open(fp)
}

func (*NormalHandler) Stat(msg *files.Message) (os.FileInfo, error) {
	fp := path.Join(msg.Service, msg.Buffer, msg.Target)
	return os.Lstat(fp)
}

func main() {
	fh := files.Handle("/path/to/dir")
	fh.Add("/myfile", NewNormal())

	// [...]
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Files

type Files struct {
	// contains filtered or unexported fields
}

Files facilitates access to the functions of the sythetic files

func NewFiles

func NewFiles(dir string, cmd chan *command.Command, tabs *tabs.Manager, feed *routes.FeedHandler) *Files

func (*Files) Normal

func (f *Files) Normal(buffer, req string, uuid uint32) (interface{}, error)

Normal will return an interface satisfying io.ReaderAt, io.WriterAt, and io.Closer if the file requested is a regular file If the file requested is a directory, it will synthesize an *os.FileInfo with the correct semantics

func (*Files) Stat

func (f *Files) Stat(buffer, req string, uuid uint32) (os.FileInfo, error)

Stat will synthesize an os.FileInfo (stat) for the named file, if available

type Handler

type Handler interface {
	Stat(msg *message.Message) (os.FileInfo, error)
	Normal(msg *message.Message) (interface{}, error)
}

Handler represents calls to a synthetic file

Jump to

Keyboard shortcuts

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