sysUtils

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Zip & Gzip Interfaces Use this instead of archive/zip and compress/gzip packages.

usage example

import "github.com/rudderlabs/rudder-server/utils/sysUtils"

var Zip sysUtils.ZipI = &sysUtils.Zip{}

or

var Zip sysUtils.ZipI = sysUtils.NewZip()

...

Zip.OpenReader(...)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GZip

type GZip struct{}

func (*GZip) NewReader

func (gz *GZip) NewReader(r io.Reader) (*gzip.Reader, error)

NewReader creates a new Reader reading the given reader. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r.

It is the caller's responsibility to call Close on the Reader when done.

The Reader.Header fields will be valid in the Reader returned.

func (*GZip) NewWriter

func (gz *GZip) NewWriter(w io.Writer) *gzip.Writer

NewWriter returns a new Writer. Writes to the returned writer are compressed and written to w.

It is the caller's responsibility to call Close on the Writer when done. Writes may be buffered and not flushed until Close.

Callers that wish to set the fields in Writer.Header must do so before the first call to Write, Flush, or Close.

type GZipI

type GZipI interface {
	NewReader(r io.Reader) (*gzip.Reader, error)
	NewWriter(w io.Writer) *gzip.Writer
}

func NewGZip

func NewGZip() GZipI

NewZip returns a Zip instance

type Http

type Http struct{}

func NewHttp

func NewHttp() *Http

NewHttp returns a Http instance

func (*Http) NewRequest

func (gz *Http) NewRequest(method string, url string, body io.Reader) (*http.Request, error)

NewRequest wraps NewRequestWithContext using the background context.

type HttpI

type HttpI interface {
	NewRequest(method string, url string, body io.Reader) (*http.Request, error)
}

type Io

type Io struct{}

func (*Io) Copy

func (i *Io) Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

If src implements the WriterTo interface, the copy is implemented by calling src.WriteTo(dst). Otherwise, if dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src).

type IoI

type IoI interface {
	Copy(dst io.Writer, src io.Reader) (written int64, err error)
}

func NewIo

func NewIo() IoI

NewIo returns an Io instance

type IoUtil

type IoUtil struct{}

func (*IoUtil) NopCloser

func (iu *IoUtil) NopCloser(r io.Reader) io.ReadCloser

NopCloser returns a ReadCloser with a no-op Close method wrapping the provided Reader r.

func (*IoUtil) ReadAll

func (iu *IoUtil) ReadAll(r io.Reader) ([]byte, error)

ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

func (*IoUtil) ReadFile

func (iu *IoUtil) ReadFile(filename string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func (*IoUtil) WriteFile

func (iu *IoUtil) WriteFile(filename string, data []byte, perm os.FileMode) error

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

type IoUtilI

type IoUtilI interface {
	ReadFile(filename string) ([]byte, error)
	WriteFile(filename string, data []byte, perm os.FileMode) error
	ReadAll(r io.Reader) ([]byte, error)
	NopCloser(r io.Reader) io.ReadCloser
}

func NewIoUtil

func NewIoUtil() IoUtilI

NewIo returns an Io instance

type Os

type Os struct{}

func (*Os) Create

func (o *Os) Create(name string) (*os.File, error)

Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

func (*Os) Getenv

func (o *Os) Getenv(key string) string

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. To distinguish between an empty value and an unset value, use LookupEnv.

func (*Os) IsNotExist

func (o *Os) IsNotExist(err error) bool

IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist. It is satisfied by ErrNotExist as well as some syscall errors.

func (*Os) LookupEnv

func (o *Os) LookupEnv(key string) (string, bool)

LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func (*Os) MkdirAll

func (o *Os) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func (*Os) Open

func (o *Os) Open(name string) (*os.File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func (*Os) OpenFile

func (o *Os) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask). If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.

func (*Os) Remove

func (o *Os) Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func (*Os) Stat

func (o *Os) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

func (*Os) UserHomeDir

func (o *Os) UserHomeDir() (string, error)

UserHomeDir returns the current user's home directory.

On Unix, including macOS, it returns the $HOME environment variable. On Windows, it returns %USERPROFILE%. On Plan 9, it returns the $home environment variable.

type OsI

type OsI interface {
	IsNotExist(err error) bool
	Getenv(key string) string
	Create(name string) (*os.File, error)
	Open(name string) (*os.File, error)
	MkdirAll(path string, perm os.FileMode) error
	OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
	Remove(name string) error
	Stat(name string) (os.FileInfo, error)
	UserHomeDir() (string, error)
	LookupEnv(key string) (string, bool)
}

func NewOs

func NewOs() OsI

NewZip returns a Os instance

type Zip

type Zip struct{}

func (*Zip) FileInfoHeader

func (iu *Zip) FileInfoHeader(fi os.FileInfo) (*zip.FileHeader, error)

FileInfoHeader creates a partially-populated FileHeader from an os.FileInfo. Because os.FileInfo's Name method returns only the base name of the file it describes, it may be necessary to modify the Name field of the returned header to provide the full path name of the file. If compression is desired, callers should set the FileHeader.Method field; it is unset by default.

func (*Zip) NewWriter

func (iu *Zip) NewWriter(w io.Writer) *zip.Writer

NewWriter returns a new Writer writing a zip file to w.

func (*Zip) OpenReader

func (iu *Zip) OpenReader(name string) (*zip.ReadCloser, error)

OpenReader will open the Zip file specified by name and return a ReadCloser.

type ZipI

type ZipI interface {
	NewWriter(w io.Writer) *zip.Writer
	FileInfoHeader(fi os.FileInfo) (*zip.FileHeader, error)
	OpenReader(name string) (*zip.ReadCloser, error)
}

func NewZip

func NewZip() ZipI

NewZip returns a Zip instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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