Check-in [2b049247ed]
Overview
Comment:Removed the decompressor alias type from predictor, use ioutil.ReaderFunc
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2b049247ed325604784b02ea16571bd0f6bb5a62
User & Date: spaskalev on 2014-12-23 08:15:45
Other Links: manifest | tags
Context
2014-12-23
09:32
Removed the compressor alias type from predictor, use ioutil.WriterFunc check-in: c62581c2a6 user: spaskalev tags: trunk
08:15
Removed the decompressor alias type from predictor, use ioutil.ReaderFunc check-in: 2b049247ed user: spaskalev tags: trunk
07:52
Added package ioutil with io.Writer and io.Reader function wrappers check-in: 2bcd5307ea user: spaskalev tags: trunk
Changes

Modified src/0dev.org/predictor/predictor.go from [290c8bbbe5] to [4bb1d52139].

     1      1   // Package predictor implements the predictor compression/decompression algorithm
     2      2   // as specified by RFC1978 - PPP Predictor Compression Protocol
     3      3   package predictor
     4      4   
     5      5   import (
     6      6   	bits "0dev.org/bits"
            7  +	iou "0dev.org/ioutil"
     7      8   	"io"
     8      9   )
     9     10   
    10     11   type context struct {
    11     12   	table [1 << 16]byte
    12     13   	input []byte
    13     14   	hash  uint16
................................................................................
   114    115   
   115    116   		return nil
   116    117   	}
   117    118   
   118    119   	return write
   119    120   }
   120    121   
   121         -// A function type alias so that it can have methods attached to it
   122         -type decompressor func([]byte) (int, error)
   123         -
   124         -// Required to implement io.Reader
   125         -func (r decompressor) Read(output []byte) (int, error) {
   126         -	return r(output)
   127         -}
   128         -
   129    122   // Returns an io.Reader implementation that wraps the provided io.Reader
   130    123   // and decompresses data according to the predictor algorithm
   131    124   func Decompressor(reader io.Reader) io.Reader {
   132    125   	var ctx context
   133    126   	ctx.input = make([]byte, 0, 8)
   134    127   
   135         -	return decompressor(func(output []byte) (int, error) {
          128  +	return iou.ReaderFunc(func(output []byte) (int, error) {
   136    129   		var (
   137    130   			err               error
   138    131   			flags, predicted  byte
   139    132   			rc, total, copied int
   140    133   		)
   141    134   
   142    135   		// Sanity check for space to read into