Overview
Comment: | Renamed BlockReader to SizedReader, modified ioutil tests for 100% code coverage |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
11d1c50cd5867c495edb33f76a2fd7c8 |
User & Date: | spaskalev on 2014-12-23 20:53:40 |
Other Links: | manifest | tags |
Context
2014-12-24
| ||
08:24 | Added an explicit copyright notice in the code. check-in: ffd1ab7b0c user: spaskalev tags: trunk | |
2014-12-23
| ||
20:53 | Renamed BlockReader to SizedReader, modified ioutil tests for 100% code coverage check-in: 11d1c50cd5 user: spaskalev tags: trunk | |
19:18 | Fixing ioutil tests to compile :) check-in: b0ff11dfcd user: spaskalev tags: trunk | |
Changes
Modified src/0dev.org/ioutil/ioutil.go from [f63ac1dff8] to [98f8caa018].
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
type ReaderFunc func([]byte) (int, error) // Delegates the call to the WriterFunc while implementing io.Reader func (r ReaderFunc) Read(b []byte) (int, error) { return r(b) } // Returns a reader that will delegate calls to Read(...) while ensuring // that the output buffer will never be smaller than the required size // and will be downsized to a multiple of the required size if larger func BlockReader(reader io.Reader, size int) io.Reader { var buffer []byte = make([]byte, 0, size) return ReaderFunc(func(output []byte) (int, error) { var ( readCount int err error ) |
| | | | |
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
type ReaderFunc func([]byte) (int, error) // Delegates the call to the WriterFunc while implementing io.Reader func (r ReaderFunc) Read(b []byte) (int, error) { return r(b) } // Returns a reader that delegates calls to Read(...) while ensuring // that the output buffer is never smaller than the required size // and is downsized to a multiple of the required size if larger func SizedReader(reader io.Reader, size int) io.Reader { var buffer []byte = make([]byte, 0, size) return ReaderFunc(func(output []byte) (int, error) { var ( readCount int err error ) |
Modified src/0dev.org/ioutil/ioutil_test.go from [a857b5c640] to [f071d3739a].
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
func TestBlockReader(t *testing.T) { var ( input []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7} output []byte = make([]byte, 16) reader *bytes.Reader = bytes.NewReader(input) min io.Reader = BlockReader(reader, 4) ) // Expecting a read count of 2 count, err := min.Read(output[:2]) if count != 2 { t.Error("Invalid read count from MinReader", count) } ................................................................................ t.Error("Invalid read count from MinReader", count) } if err != nil { t.Error("Unexpected error from MinReader", err) } // Expecting a read count of 0 with an EOF as the buffer should be empty count, err = min.Read(output[:4]) if count != 0 { t.Error("Invalid read count from MinReader", count) } if err != io.EOF { t.Error("Unexpected error from MinReader", err) } } |
|
|
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
func TestBlockReader(t *testing.T) { var ( input []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7} output []byte = make([]byte, 16) reader *bytes.Reader = bytes.NewReader(input) min io.Reader = SizedReader(reader, 4) ) // Expecting a read count of 2 count, err := min.Read(output[:2]) if count != 2 { t.Error("Invalid read count from MinReader", count) } ................................................................................ t.Error("Invalid read count from MinReader", count) } if err != nil { t.Error("Unexpected error from MinReader", err) } // Expecting a read count of 0 with an EOF as the buffer should be empty count, err = min.Read(output[:1]) if count != 0 { t.Error("Invalid read count from MinReader", count) } if err != io.EOF { t.Error("Unexpected error from MinReader", err) } } |
Modified src/0dev.org/predictor/predictor.go from [625ed7e8bc] to [1bc0c5d728].
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
// 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.BlockReader(iou.ReaderFunc(func(output []byte) (int, error) {
var (
err error
flags, predicted byte
rc, total, copied int
)
// Read the next prediction header
|
| |
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
// 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.SizedReader(iou.ReaderFunc(func(output []byte) (int, error) {
var (
err error
flags, predicted byte
rc, total, copied int
)
// Read the next prediction header
|