本文整理汇总了Golang中io.PipeReader.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang PipeReader.Close方法的具体用法?Golang PipeReader.Close怎么用?Golang PipeReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.PipeReader
的用法示例。
在下文中一共展示了PipeReader.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: process
func (c *clientBuildTrace) process(pipe *io.PipeReader) {
defer pipe.Close()
stopped := false
limit := c.config.OutputLimit
if limit == 0 {
limit = common.DefaultOutputLimit
}
limit *= 1024
reader := bufio.NewReader(pipe)
for {
r, s, err := reader.ReadRune()
if s <= 0 {
break
} else if stopped {
// ignore symbols if build log exceeded limit
continue
} else if err == nil {
_, err = c.writeRune(r, limit)
if err == io.EOF {
stopped = true
}
} else {
// ignore invalid characters
continue
}
}
}
示例2: readTrace
func (e *AbstractExecutor) readTrace(pipe *io.PipeReader) {
defer e.Debugln("ReadTrace finished")
traceStopped := false
traceOutputLimit := helpers.NonZeroOrDefault(e.Config.OutputLimit, common.DefaultOutputLimit)
traceOutputLimit *= 1024
reader := bufio.NewReader(pipe)
for {
r, s, err := reader.ReadRune()
if s <= 0 {
break
} else if traceStopped {
// ignore symbols if build log exceeded limit
continue
} else if err == nil {
e.Build.WriteRune(r)
} else {
// ignore invalid characters
continue
}
if e.Build.BuildLogLen() > traceOutputLimit {
output := fmt.Sprintf("\n%sBuild log exceeded limit of %v bytes.%s\n",
helpers.ANSI_BOLD_RED,
traceOutputLimit,
helpers.ANSI_RESET,
)
e.Build.WriteString(output)
traceStopped = true
}
}
pipe.Close()
}
示例3: ReadTrace
func (e *AbstractExecutor) ReadTrace(pipe *io.PipeReader) {
defer e.Debugln("ReadTrace finished")
traceStopped := false
reader := bufio.NewReader(pipe)
for {
r, s, err := reader.ReadRune()
if s <= 0 {
break
} else if traceStopped {
// ignore symbols if build log exceeded limit
continue
} else if err == nil {
e.Build.WriteRune(r)
} else {
// ignore invalid characters
continue
}
if e.Build.BuildLogLen() > common.MaxTraceOutputSize {
output := fmt.Sprintf("\nBuild log exceeded limit of %v bytes.", common.MaxTraceOutputSize)
e.Build.WriteString(output)
traceStopped = true
break
}
}
pipe.Close()
}
示例4: writerScanner
func (logger *Logger) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
printFunc(scanner.Text())
}
if err := scanner.Err(); err != nil {
logger.Errorf("Error while reading from Writer: %s", err)
}
reader.Close()
}
示例5: writerScanner
func (logger *Logger) writerScanner(reader *io.PipeReader) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
logger.Print(scanner.Text())
}
if err := scanner.Err(); err != nil {
logger.Errorf("Error while reading from Writer: %s", err)
}
reader.Close()
}
示例6: logWriterScanner
func logWriterScanner(logger *logrus.Entry, reader *io.PipeReader) {
defer reader.Close()
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
logger.Print(scanner.Text())
}
if err := scanner.Err(); err != nil {
if err == io.EOF {
return
}
logger.Errorf("Error while reading from Writer: %s", err)
}
}
示例7: logWriterScanner
func logWriterScanner(logger *logrus.Logger, reader *io.PipeReader) {
defer reader.Close()
// 64k max per line
buf := bufio.NewReaderSize(reader, 1024*64)
for {
line, _, err := buf.ReadLine()
if err != nil {
if err == io.EOF {
break
}
logger.Errorf("Error while reading from Writer: %s", err)
return
}
logger.Print(string(line))
}
}
示例8: writeCmdOutput
func writeCmdOutput(res http.ResponseWriter, pipeReader *io.PipeReader) {
buffer := make([]byte, BUF_LEN)
for {
n, err := pipeReader.Read(buffer)
if err != nil {
pipeReader.Close()
break
}
data := buffer[0:n]
res.Write(data)
if f, ok := res.(http.Flusher); ok {
f.Flush()
}
//reset buffer
for i := 0; i < n; i++ {
buffer[i] = 0
}
}
}
示例9: StartProbe
func StartProbe(path string) (ret *ProbeCmd, err error) {
if ffprobePath == "" {
err = FfprobeUnavailableError
return
}
cmd := exec.Command(ffprobePath,
"-loglevel", "error",
"-show_format",
"-show_streams",
outputFormatFlag, "json",
path)
setHideWindow(cmd)
var stdout, stderr *io.PipeReader
stdout, cmd.Stdout = io.Pipe()
stderr, cmd.Stderr = io.Pipe()
err = cmd.Start()
if err != nil {
return
}
ret = &ProbeCmd{
Cmd: cmd,
Done: make(chan struct{}),
}
lastLineCh := make(chan string, 1)
ret.mu.Lock()
go func() {
defer close(ret.Done)
err := cmd.Wait()
stdout.Close()
stderr.Close()
ret.mu.Lock()
defer ret.mu.Unlock()
if err == nil {
return
}
lastLine, ok := <-lastLineCh
if ok {
err = fmt.Errorf("%s: %s", err, lastLine)
}
ret.Err = err
}()
go lastLine(stderr, lastLineCh)
go func() {
decoder := json.NewDecoder(bufio.NewReader(stdout))
ret.Err = decoder.Decode(&ret.Info)
ret.mu.Unlock()
stdout.Close()
}()
return
}