peechee

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: MIT Imports: 11 Imported by: 2

README

PeeChee

PeeChee?

Description

PeeChee is a simple library for accessing filepaths (mostly) backend-agnostically.

Example

import (
    "io/ioutil"

    "github.com/daihasso/peechee"
)

var pathReader *peechee.PathReader

func main() {
    myS3Client := MakeMyS3Client()
    pathReader = peechee.NewPathReader(
        peechee.WithFilesystem(), peechee.WithS3(myS3Client),
    )

    localResultReader, err := pathReader.Read("my/local/config.yaml")
    if err != nil {
        panic(err)
    }

    localConfigBytes, err := ioutil.ReadAll(localResultReader)
    if err != nil {
        panic(err)
    }

    cloudResultReader, err := pathReader.Read("s3://my-bucket/config.yaml")
    if err != nil {
        panic(err)
    }

    cloudConfigBytes, err := ioutil.ReadAll(cloudResultReader)
    if err != nil {
        panic(err)
    }

    // Do stuff with all these configs.
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithFilesystem

func WithFilesystem() option

WithFilesystem adds filesystem compatibility to the PathReader.

func WithS3

func WithS3(s3Client s3iface.S3API) option

WithS3 adds S3 compatiblity to the PathReader.

Types

type PathReader

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

func NewPathReader

func NewPathReader(options ...option) *PathReader

NewPathReader creates a path reader with the provided options.

func (*PathReader) AddOption added in v0.0.2

func (self *PathReader) AddOption(options ...option)

func (PathReader) Read

func (self PathReader) Read(path string) (io.Reader, error)

Read reads a path to a io.Reader for consumption later.

func (PathReader) ReadTo

func (self PathReader) ReadTo(path string, wa io.WriterAt) error

ReadTo reads a path to a provided io.WriterAt instance.

type WriteAtBuffer

type WriteAtBuffer struct {

	// GrowthCoeff defines the growth rate of the internal buffer. By
	// default, the growth rate is 1, where expanding the internal
	// buffer will allocate only enough capacity to fit the new expected
	// length.
	GrowthCoeff float64
	// contains filtered or unexported fields
}

A WriteAtBuffer provides a in memory buffer supporting the io.WriterAt interface can be used with the s3manager.Downloader to download content to a buffer in memory. Safe to use concurrently.

func NewWriteAtBuffer

func NewWriteAtBuffer(buf []byte) *WriteAtBuffer

NewWriteAtBuffer creates a WriteAtBuffer with an internal buffer provided by buf.

func (*WriteAtBuffer) Bytes

func (b *WriteAtBuffer) Bytes() []byte

Bytes returns a slice of bytes written to the buffer.

func (*WriteAtBuffer) WriteAt

func (b *WriteAtBuffer) WriteAt(p []byte, pos int64) (n int, err error)

WriteAt writes a slice of bytes to a buffer starting at the position provided the number of bytes written will be returned, or error. Can overwrite previous written slices if the write ats overlap.

Jump to

Keyboard shortcuts

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