pipe

package module
v0.0.0-...-be78f12 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2017 License: MIT Imports: 4 Imported by: 1

README

pipe Go Report Card GoDoc

small package for reading pipe data

Installation

go get -u github.com/yaronsumel/pipe

Sync Usage

Read is Sync Action to get all pipe data fits in the predifened size

	data,err := pipe.Read(pipe.Stdin,1024)
	if err!=nil{
		//do something with the error
	}

Async Usage

AyncRead will keep reading from the pipe and write it back to StdDataChannel. Don't forget to handle the errors.

	StdinChannel := make(pipe.StdDataChannel)
	go pipe.AsyncRead(pipe.Stdin, 1024, StdinChannel)
	for {
		select {
		case stdin := <-StdinChannel:
			if stdin.Err != nil {
				panic(stdin.Err)
			}
			fmt.Println(stdin.Data)
		}
	}

Working Example

get the command

go get -u github.com/yaronsumel/pipe/pipe-example

run it.pipe it.that's it.

pipe-example --write | pipe-example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Stdin  = os.Stdin
	Stdout = os.Stdout
	Stderr = os.Stderr
)

used here to prevent os package import

Functions

func AsyncRead

func AsyncRead(pipe io.Reader, bufSize int, stdDataChan chan StdData)

AsyncRead keeps reading from io.reader into buffer return data in stdData structure use in only with routine - ie go AsyncRead

func IsNamedPipe

func IsNamedPipe() bool

IsNamedPipe checks whether valid pipe used

func Read

func Read(pipe io.Reader, bufSize int) ([]byte, error)

Read reads from io.reader one chunk as defined as bufSize

Types

type StdData

type StdData struct {
	Data []byte
	Err  error
}

StdData is used as channel structure

type StdDataChannel

type StdDataChannel chan StdData

StdDataChannel used for as async communication channel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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