iokit

package module
v0.0.0-...-20a8322 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: Apache-2.0 Imports: 20 Imported by: 8

README

CircleCI Maintainability Test Coverage Go Report Card License

 // S3Url uses S3_*_URL environment variables
 // export S3_DOTEST_URL=s3://id:secret@nyc3.digitaloceanspaces.com/bucket/prefix
 // export S3_AWSTEST_URL=s3://id:secret@s3.us-west-2.amazonaws.com/bucket/prefix
 // s3://$cerds/path means to use credentials form environment valiable S3_CREDS_URL
 // s3://$/bucket/path means to use default aws credentials
 //
 // GsUrl uses GS_*_URL environment variables
 // export GS_ENCTEST_URL=json://bucket:prefix:password:/abs/path/to/servicecredentials.json.enc
 // export GS_TEST_URL=json://bucket:prefix::/abs/path/to/servicecredentials.json
 // gs://$creds/path menas to use credentials form enviroment variable GS_CREDS_URL
 // gs://$/bucket/path means to use default google cloud credentials
 //
 // File url can use any environment variable
 // export FILES=.

// Write and read back 
func Test_Example(t *testing.T) {
    for _,url := range []string{
                        "s3://$awstest/test_example.txt",
                        "gs://$enctest/test_example.txt",
                        "file://$files/test_example.txt"} {
        
        S := fmt.Sprintf(`Hello world! %d`, rand.Int())
    
        wh,err := iokit.Url(url).Create()
        assert.NilError(t,err)
        defer wh.End()
        _,err = wh.Write([]byte(S))
        assert.NilError(t,err)
        err = wh.Commit()
        assert.NilError(t,err)
    
        rd,err := iokit.Url(url).Open()
        assert.NilError(t,err)
        defer rd.Close()
        q,err := ioutil.ReadAll(rd)
        assert.NilError(t,err)
        assert.Assert(t,string(q)==S)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FullCacheDir string

Functions

func CacheDir

func CacheDir(d string) string

func CacheFile

func CacheFile(f string) string

func Decompress

func Decompress(source interface{}) io.ReadCloser

func Download

func Download(url string, writer io.Writer) error

func FileSize

func FileSize(rd io.Reader) int64

func Reader

func Reader(rd io.Reader, close ...func() error) reader

func ResetFile

func ResetFile(rd io.Reader) error

func Upload

func Upload(url string, reader io.Reader) error

func Writer

func Writer(wr io.Writer, close ...func(bool) error) writer

Types

type AsyncUpload

type AsyncUpload struct{ Notify func(url string, err error) }

type Cache

type Cache string

func (Cache) Defined

func (c Cache) Defined() bool

func (Cache) Exists

func (c Cache) Exists() bool

func (Cache) File

func (c Cache) File() InputOutput

func (Cache) LuckyOpen

func (c Cache) LuckyOpen() LuckyReader

func (Cache) Open

func (c Cache) Open() (io.ReadCloser, error)

func (Cache) Path

func (c Cache) Path() string

func (Cache) Remove

func (c Cache) Remove() (err error)

func (Cache) String

func (c Cache) String() string

type CloserChain

type CloserChain []io.Closer

func (CloserChain) Close

func (c CloserChain) Close() error

type Fallible

type Fallible interface {
	Fail()
}

type GsUrl

type GsUrl string

func (GsUrl) Download

func (gsurl GsUrl) Download(wr io.Writer) error

func (GsUrl) Upload

func (gsurl GsUrl) Upload(rd io.Reader, metadata ...map[string]string) error

type HttpUrl

type HttpUrl string

func (HttpUrl) Download

func (url HttpUrl) Download(wr io.Writer) error

type Input

type Input interface {
	Open() (io.ReadCloser, error)
}

type InputOutput

type InputOutput interface {
	Input
	Output
}

type IoUrl

type IoUrl struct {
	Url      string
	Schema   string
	Cache    Cache
	Observer AsyncUpload
	Metadata Metadata
}

func (IoUrl) Create

func (iourl IoUrl) Create() (hw Whole, err error)

func (IoUrl) Download

func (iourl IoUrl) Download(wr io.Writer) error

func (IoUrl) Open

func (iourl IoUrl) Open() (rd io.ReadCloser, err error)

func (IoUrl) Upload

func (iourl IoUrl) Upload(rd io.Reader) error

type LuckyInput

type LuckyInput struct{ Input }

func Compressed

func Compressed(arch interface{}) LuckyInput

func StringIO

func StringIO(str string) LuckyInput

func ZipFile

func ZipFile(fileName string, arch Input) LuckyInput

func (LuckyInput) LuckyOpen

func (iox LuckyInput) LuckyOpen() LuckyReader

func (LuckyInput) LuckyReadAll

func (iox LuckyInput) LuckyReadAll() []byte

func (LuckyInput) ReadAll

func (iox LuckyInput) ReadAll() ([]byte, error)

type LuckyInputOutput

type LuckyInputOutput struct{ InputOutput }

func File

func File(path string) LuckyInputOutput

func Url

func Url(url string, opts ...interface{}) LuckyInputOutput

func (LuckyInputOutput) LuckyCreate

func (iox LuckyInputOutput) LuckyCreate() LuckyWhole

func (LuckyInputOutput) LuckyOpen

func (iox LuckyInputOutput) LuckyOpen() LuckyReader

func (LuckyInputOutput) LuckyReadAll

func (iox LuckyInputOutput) LuckyReadAll() []byte

func (LuckyInputOutput) LuckyWriteAll

func (iox LuckyInputOutput) LuckyWriteAll(bs []byte)

func (LuckyInputOutput) ReadAll

func (iox LuckyInputOutput) ReadAll() ([]byte, error)

func (LuckyInputOutput) WriteAll

func (iox LuckyInputOutput) WriteAll(bs []byte) error

type LuckyOutput

type LuckyOutput struct{ Output }

func Gzip

func Gzip(output Output) LuckyOutput

func Lzma2

func Lzma2(output Output) LuckyOutput

func Zip

func Zip(fileName string, arch Output) LuckyOutput

func (LuckyOutput) LuckyCreate

func (iox LuckyOutput) LuckyCreate() LuckyWhole

func (LuckyOutput) LuckyWriteAll

func (iox LuckyOutput) LuckyWriteAll(bs []byte)

func (LuckyOutput) WriteAll

func (iox LuckyOutput) WriteAll(bs []byte) error

type LuckyReader

type LuckyReader struct{ io.ReadCloser }

func (LuckyReader) LuckyReadAll

func (lr LuckyReader) LuckyReadAll() []byte

type LuckyWhole

type LuckyWhole struct{ Whole }

func (LuckyWhole) LuckyCommit

func (lr LuckyWhole) LuckyCommit()

func (LuckyWhole) LuckyWrite

func (lw LuckyWhole) LuckyWrite(b []byte)

type Metadata

type Metadata map[string]string

type Output

type Output interface {
	Create() (Whole, error)
}

type Resettable

type Resettable interface {
	Reset() error
}

type S3Url

type S3Url string

func (S3Url) Download

func (s3url S3Url) Download(wr io.Writer) error

func (S3Url) Upload

func (s3url S3Url) Upload(rd io.Reader, metadata ...map[string]string) error

type Sizeable

type Sizeable interface {
	Size() int64
}

type TemporaryFile

type TemporaryFile interface {
	Whole
	io.Reader
	io.Closer
	Truncate() error
	Reset() error
}

func Tempfile

func Tempfile(pattern string) (_ TemporaryFile, err error)

type VersionType

type VersionType int
const Version VersionType = 10000

func (VersionType) Major

func (v VersionType) Major() int

func (VersionType) Minor

func (v VersionType) Minor() int

func (VersionType) Patch

func (v VersionType) Patch() int

func (VersionType) String

func (v VersionType) String() string

type Whole

type Whole interface {
	io.Writer
	Commit() error
	End()
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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