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 ¶
- type GZip
- type GZipI
- type HTTPClientI
- type Http
- type HttpI
- type Io
- type IoI
- type IoUtil
- type IoUtilI
- type Os
- func (o *Os) Create(name string) (*os.File, error)
- func (o *Os) Getenv(key string) string
- func (o *Os) IsNotExist(err error) bool
- func (o *Os) LookupEnv(key string) (string, bool)
- func (o *Os) MkdirAll(path string, perm os.FileMode) error
- func (o *Os) Open(name string) (*os.File, error)
- func (o *Os) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func (o *Os) Remove(name string) error
- func (o *Os) Stat(name string) (os.FileInfo, error)
- func (o *Os) UserHomeDir() (string, error)
- type OsI
- type Zip
- type ZipI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GZip ¶
type GZip struct{}
func (*GZip) NewReader ¶
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 ¶
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 HTTPClientI ¶
HTTPClient interface
type Io ¶
type Io struct{}
func (*Io) Copy ¶
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 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 ¶
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.
type IoUtilI ¶
type Os ¶
type Os struct{}
func (*Os) Create ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.
func (*Os) Stat ¶
Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.
func (*Os) UserHomeDir ¶
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) }
type Zip ¶
type Zip struct{}
func (*Zip) FileInfoHeader ¶
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) OpenReader ¶
func (iu *Zip) OpenReader(name string) (*zip.ReadCloser, error)
OpenReader will open the Zip file specified by name and return a ReadCloser.