当前位置: 首页>>代码示例>>Golang>>正文


Golang io.PipeReader类代码示例

本文整理汇总了Golang中io.PipeReader的典型用法代码示例。如果您正苦于以下问题:Golang PipeReader类的具体用法?Golang PipeReader怎么用?Golang PipeReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PipeReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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()
}
开发者ID:mikew,项目名称:gitlab-ci-multi-runner,代码行数:35,代码来源:executor_trace.go

示例2: startReading

// startReading starts a goroutine receiving the lines out of the reader
// in the background and passing them to a created string channel. This
// will used in the assertions.
func startReading(c *gc.C, tailer *tailer.Tailer, reader *io.PipeReader, writer *io.PipeWriter) chan string {
	linec := make(chan string)
	// Start goroutine for reading.
	go func() {
		defer close(linec)
		reader := bufio.NewReader(reader)
		for {
			line, err := reader.ReadString('\n')
			switch err {
			case nil:
				linec <- line
			case io.EOF:
				return
			default:
				c.Fail()
			}
		}
	}()
	// Close writer when tailer is stopped or has an error. Tailer using
	// components can do it the same way.
	go func() {
		tailer.Wait()
		writer.Close()
	}()
	return linec
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:tailer_test.go

示例3: secWriteLoop

// secWriteLoop copies data from pr into w
// doing a nacl seal encryption on the data in the process using shared as the key
func secWriteLoop(w io.Writer, pr *io.PipeReader, shared *[32]byte) {
	var failed bool
	// check for an error, stops the loop and
	// closes the pipe with err to signal the writer we failed
	var check = func(err error) {
		if err != nil {
			log.Println("secWriteLoop err:", err)
			if err2 := pr.CloseWithError(err); err2 != nil {
				log.Println("CloseWithError failed", err2)
			}
			failed = true
		}
	}
	for !failed { // until an error occurs
		// read the clear message from our pipe
		msg := make([]byte, 1024)
		n, err := pr.Read(msg)
		check(err)

		// cut of the unused bytes
		msg = msg[:n]

		// read 24 bytes of random for our nonce
		var nonce [24]byte
		_, err = io.ReadFull(rand.Reader, nonce[:])
		check(err)

		// encrypt and sign our message with the prepended nonce
		buf := box.SealAfterPrecomputation(nonce[:], msg, &nonce, shared)

		// copy the sealed message with our passed writer
		_, err = io.Copy(w, bytes.NewReader(buf))
		check(err)
	}
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:37,代码来源:main.go

示例4: 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
		}
	}
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:29,代码来源:build.go

示例5: 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()
}
开发者ID:AdrianoJS,项目名称:gitlab-ci-multi-runner,代码行数:30,代码来源:executor_abstract.go

示例6: 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()
}
开发者ID:CM44,项目名称:shipyard,代码行数:10,代码来源:writer.go

示例7: 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()
}
开发者ID:CMartinUdden,项目名称:authz,代码行数:10,代码来源:writer.go

示例8: PipeRead

func PipeRead(pipeReader *io.PipeReader) {
	var (
		err error
		n   int
	)
	data := make([]byte, 1024)
	for n, err = pipeReader.Read(data); err == nil; n, err = pipeReader.Read(data) {
		fmt.Printf("%s\n", data[:n])
	}
	fmt.Println("writer 端 closewitherror后:", err)
}
开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:11,代码来源:PipRW.go

示例9: 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)
	}
}
开发者ID:fd,项目名称:switchboard,代码行数:14,代码来源:driver.go

示例10: Write

func (w *imageProgressWriter) Write(data []byte) (int, error) {
	w.mutex.Lock()
	defer w.mutex.Unlock()
	if w.internalWriter == nil {
		var pipeIn *io.PipeReader
		pipeIn, w.internalWriter = io.Pipe()
		decoder := json.NewDecoder(pipeIn)
		go func() {
			err := w.readProgress(decoder)
			if err != nil {
				pipeIn.CloseWithError(err)
			}
		}()
	}
	return w.internalWriter.Write(data)
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:16,代码来源:progress.go

示例11: 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))
	}
}
开发者ID:romank87,项目名称:rocker,代码行数:18,代码来源:writer.go

示例12: 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
		}
	}
}
开发者ID:voidabhi,项目名称:golang-scripts,代码行数:20,代码来源:http-pipe.go

示例13: 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
}
开发者ID:ronindev,项目名称:dms,代码行数:50,代码来源:ffmpeg.go

示例14: startRead

func startRead(reader *io.PipeReader) {
	v := make([]byte, 100)
	_, _ = reader.Read(v)
	fmt.Println(string(v))
}
开发者ID:haetze,项目名称:DemoGO,代码行数:5,代码来源:pipeExample.go

示例15: HandleWrite

func HandleWrite(filename string, r *io.PipeReader) {
	r.CloseWithError(fmt.Errorf("Server is Read Only"))
}
开发者ID:gumyn,项目名称:astralboot,代码行数:3,代码来源:tftp.go


注:本文中的io.PipeReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。