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
2
3
4
5
6

7
8
9
10
11
12
13
...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Package predictor implements the predictor compression/decompression algorithm
// as specified by RFC1978 - PPP Predictor Compression Protocol
package predictor

import (
	bits "0dev.org/bits"

	"io"
)

type context struct {
	table [1 << 16]byte
	input []byte
	hash  uint16
................................................................................

		return nil
	}

	return write
}

// A function type alias so that it can have methods attached to it
type decompressor func([]byte) (int, error)

// Required to implement io.Reader
func (r decompressor) Read(output []byte) (int, error) {
	return r(output)
}

// Returns an io.Reader implementation that wraps the provided io.Reader
// and decompresses data according to the predictor algorithm
func Decompressor(reader io.Reader) io.Reader {
	var ctx context
	ctx.input = make([]byte, 0, 8)

	return decompressor(func(output []byte) (int, error) {
		var (
			err               error
			flags, predicted  byte
			rc, total, copied int
		)

		// Sanity check for space to read into






>







 







<
<
<
<
<
<
<
<






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
115
116
117
118
119
120
121








122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Package predictor implements the predictor compression/decompression algorithm
// as specified by RFC1978 - PPP Predictor Compression Protocol
package predictor

import (
	bits "0dev.org/bits"
	iou "0dev.org/ioutil"
	"io"
)

type context struct {
	table [1 << 16]byte
	input []byte
	hash  uint16
................................................................................

		return nil
	}

	return write
}









// Returns an io.Reader implementation that wraps the provided io.Reader
// and decompresses data according to the predictor algorithm
func Decompressor(reader io.Reader) io.Reader {
	var ctx context
	ctx.input = make([]byte, 0, 8)

	return iou.ReaderFunc(func(output []byte) (int, error) {
		var (
			err               error
			flags, predicted  byte
			rc, total, copied int
		)

		// Sanity check for space to read into