fsadapter

package
v2.5.5 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: GPL-3.0, BSD-3-Clause Imports: 12 Imported by: 0

README

fsadapter - File System adapter

Go Reference

fsadapter is a wrapper for writing to directory or a ZIP file.

There are currently 2 adapters:

  • Directory
  • ZIP

Each adapter exposes the following methods:

  • Create(string) (io.WriteCloser, error)
  • WriteFile(name string, data []byte, perm os.FileMode) error
  • Close() error

It is meant to be a drop-in replacement for os.* functions for Slackdump.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIllegalDir = errors.New("illegal file path reference outside of working directory")

ErrIllegalDir is returned, if the file path reference is outside of the working directory.

Functions

This section is empty.

Types

type Directory

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

func NewDirectory

func NewDirectory(dir string) Directory

NewDirectory returns a new Directory filesystem adapter for a given directory.

func (Directory) Close added in v2.3.4

func (fs Directory) Close() error

Close is a noop for Directory.

func (Directory) Create

func (fs Directory) Create(fpath string) (io.WriteCloser, error)

Create creates a new file in the directory.

func (Directory) String

func (d Directory) String() string

func (Directory) WriteFile

func (fs Directory) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to a file named by name. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing.

type FS

type FS interface {
	Create(string) (io.WriteCloser, error)
	WriteFile(name string, data []byte, perm os.FileMode) error
}

FS is interface for operating on the files of the underlying filesystem.

type FSCloser added in v2.3.4

type FSCloser interface {
	FS
	io.Closer
}

FSCloser is a FS that can be closed.

func New added in v2.3.4

func New(location string) (FSCloser, error)

New returns appropriate filesystem based on the name of the location. Logic is simple:

  • if location has a known extension, the appropriate adapter is returned.
  • else: it's a directory.

Currently supported extensions: ".zip" (case insensitive)

type ZIP

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

ZIP is a filesystem adapter for zip files.

func NewZIP

func NewZIP(zw *zip.Writer) *ZIP

NewZIP returns a new ZIP filesystem adapter for a given ZipWriter.

func NewZipFile

func NewZipFile(filename string) (*ZIP, error)

NewZipFile returns a new ZIP filesystem adapter for a given filename.

func (*ZIP) Close

func (z *ZIP) Close() error

Close closes the underlying zip writer and the file handle. It is only necessary if ZIP was initialised using NewZipFile

func (*ZIP) Create

func (z *ZIP) Create(filename string) (io.WriteCloser, error)

Create creates a new file in the zip archive.

func (*ZIP) String

func (z *ZIP) String() string

func (*ZIP) WriteFile

func (z *ZIP) WriteFile(filename string, data []byte, _ os.FileMode) error

WriteFile writes the given data to the given filename in the zip archive.

Jump to

Keyboard shortcuts

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