github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/pipebomb.go (about) 1 package cloudcontroller 2 3 import ( 4 "io" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 ) 8 9 // Pipebomb is a wrapper around an io.Pipe's io.ReadCloser that turns it into a 10 // ReadSeeker that errors on Seek calls. This is designed to prevent the caller 11 // from rereading the body multiple times. 12 type Pipebomb struct { 13 io.ReadCloser 14 } 15 16 // Seek returns a PipeSeekError; allowing the top level calling function to 17 // handle the retry instead of seeking back to the beginning of the Reader. 18 func (*Pipebomb) Seek(offset int64, whence int) (int64, error) { 19 return 0, ccerror.PipeSeekError{} 20 } 21 22 // NewPipeBomb returns an io.WriteCloser that can be used to stream data to a 23 // the Pipebomb. 24 func NewPipeBomb() (*Pipebomb, io.WriteCloser) { 25 writerOutput, writerInput := io.Pipe() 26 return &Pipebomb{ReadCloser: writerOutput}, writerInput 27 }