util

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ext

func Ext(p string) string

Ext will retrieve a non-compression related file extension. If there are multiple, it returns the first behind the compression extension. It is assumed the compression extension is last.

Only supports '.gz' at the moment.

func OpenTmp

func OpenTmp(dir, prefix string) (absTmp string, f *os.File, err error)

OpenTmp will open and create a temp file It will create necessary directories.

func ParsePath

func ParsePath(pth string) (scheme, host, fPth string)

ParsePath will parse a path of the form: "{scheme}://{host}/{path/to/file.txt} and return the scheme, host and file path.

Example: "s3://my-host/path/to/file.txt"

Returns: scheme: "s3" host: "my-host" fPth: "path/to/file.txt"

func RmTmp

func RmTmp(tmpPth string) error

RmTmp will remove a local tmp file.

Types

type CloseBuf

type CloseBuf struct {
	Buf *bytes.Buffer
}

CloseBuf is a bytes.Buffer with a Close method.

func NewCloseBuf

func NewCloseBuf() *CloseBuf

NewCloseBuf returns an instance of CloseBuf.

func (CloseBuf) Close

func (b CloseBuf) Close() error

type HashCloser

type HashCloser struct {
	Hshr hash.Hash
}

func NewMD5Closer

func NewMD5Closer() *HashCloser

func (*HashCloser) Close

func (h *HashCloser) Close() error

func (*HashCloser) Write

func (h *HashCloser) Write(p []byte) (n int, err error)

type HashReader

type HashReader struct {
	Hshr hash.Hash
	// contains filtered or unexported fields
}

HashReader executes the underlying reader Read call and will write the read bytes into the hasher. This is useful when you want the hasher to get at the raw bytes of the reader.

func NewHashReader

func NewHashReader(hshr hash.Hash, r io.Reader) *HashReader

func (*HashReader) Read

func (r *HashReader) Read(p []byte) (n int, err error)

type MultiWriteCloser

type MultiWriteCloser struct {
	// contains filtered or unexported fields
}
Example
// showing:
// - write err
// - close err
// - short write err

// write, close err
errW := new(errWriteCloser)
writers := make([]io.WriteCloser, 1)
writers[0] = errW
w := NewMultiWriteCloser(writers)
_, err := w.Write([]byte("test err"))
fmt.Println(err) // error writing
err = w.Close()
fmt.Println(err) // error closing

// short write err
errShort := new(shortWriteCloser)
writers[0] = errShort
w = NewMultiWriteCloser(writers)
_, err = w.Write([]byte("test short"))
fmt.Println(err) // short write
Output:

error writing
error closing
short write

func NewMultiWriteCloser

func NewMultiWriteCloser(writers []io.WriteCloser) *MultiWriteCloser

func (*MultiWriteCloser) Close

func (mw *MultiWriteCloser) Close() (err error)

func (*MultiWriteCloser) Write

func (mw *MultiWriteCloser) Write(p []byte) (n int, err error)

type NopCloser

type NopCloser struct {
	io.Writer
}

NopCloser will turn a Writer into an io.WriteCloser Write will call the original write Write method. Close will do nothing.

func NewNopWriteCloser

func NewNopWriteCloser(w io.Writer) *NopCloser

func (*NopCloser) Close

func (wc *NopCloser) Close() error

Jump to

Keyboard shortcuts

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