dreader

package module
v0.0.0-...-991ff50 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2015 License: MIT Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dreader

Go package that implements Delayed Reader. A Reader that waits a fixed amount of time before returning.

PACKAGE DOCUMENTATION

package dreader
    import "."

    Package dreader implements a delayed reader. A Reader that waits a fixed
    amount of time before returning. A DelayedReader will block Reads a
    specific time for more data and returns once it times out.

    This package could be use for reading from a terminal where a escape
    sequence could be from one to several bytes with the only difference of
    the time

	r,w := io.Pipe()

	dr := dreader.New(r, time.Millisecond * 10)

	go func(){
	  buf := make([]byte, 1024)
	  n, err := dr.Read(buf)
	  if err != nil {
	     return err
	  }
	  buf[:n] == "hello world"
	}

	w.Write("hello")
	w.Write(" world")

VARIABLES

var DefaultSize = 1024

TYPES

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

func New(r io.Reader, delay time.Duration) *DelayedReader
    New returns a DelayedReader

func (dr *DelayedReader) Read(buf []byte) (n int, e error)
    Read returns any data in the internal buffer if there is any Then it
    returns any error in case there was any And then returns any data read
    from the from the underlaying reader. If an error is returned no more
    Read will be able to perform and a new DelayedReader should be created


Documentation

Overview

Package dreader implements a delayed reader. A Reader that waits a fixed amount of time before returning. A DelayedReader will block Reads a specific time for more data and returns once it times out.

This package could be use for reading from a terminal where a escape sequence could be from one to several bytes with the only difference of the time

r,w := io.Pipe()

dr := dreader.New(r, time.Millisecond * 10)

go func(){
  buf := make([]byte, 1024)
  n, err := dr.Read(buf)
  if err != nil {
     return err
  }
  buf[:n] == "hello world"
}

w.Write("hello")
w.Write(" world")

Index

Constants

This section is empty.

Variables

View Source
var DefaultSize = 1024

Functions

This section is empty.

Types

type DelayedReader

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

func New

func New(r io.Reader, delay time.Duration) *DelayedReader

New returns a DelayedReader

func (*DelayedReader) Read

func (dr *DelayedReader) Read(buf []byte) (n int, e error)

Read returns any data in the internal buffer if there is any Then it returns any error in case there was any And then returns any data read from the from the underlaying reader. If an error is returned no more Read will be able to perform and a new DelayedReader should be created

Jump to

Keyboard shortcuts

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