Check-in [11d1c50cd5]
Overview
SHA1:11d1c50cd5867c495edb33f76a2fd7c8e4ba1447
Date: 2014-12-23 20:53:40
User: spaskalev
Comment:Renamed BlockReader to SizedReader, modified ioutil tests for 100% code coverage
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-12-24
08:24
[ffd1ab7b0c] Added an explicit copyright notice in the code. (user: spaskalev, tags: trunk)
2014-12-23
20:53
[11d1c50cd5] Renamed BlockReader to SizedReader, modified ioutil tests for 100% code coverage (user: spaskalev, tags: trunk)
19:18
[b0ff11dfcd] Fixing ioutil tests to compile :) (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/ioutil/ioutil.go from [f63ac1dff8] to [98f8caa018].

    17     17   type ReaderFunc func([]byte) (int, error)
    18     18   
    19     19   // Delegates the call to the WriterFunc while implementing io.Reader
    20     20   func (r ReaderFunc) Read(b []byte) (int, error) {
    21     21   	return r(b)
    22     22   }
    23     23   
    24         -// Returns a reader that will delegate calls to Read(...) while ensuring
    25         -// that the output buffer will never be smaller than the required size
    26         -// and will be downsized to a multiple of the required size if larger
    27         -func BlockReader(reader io.Reader, size int) io.Reader {
           24  +// Returns a reader that delegates calls to Read(...) while ensuring
           25  +// that the output buffer is never smaller than the required size
           26  +// and is downsized to a multiple of the required size if larger
           27  +func SizedReader(reader io.Reader, size int) io.Reader {
    28     28   	var buffer []byte = make([]byte, 0, size)
    29     29   
    30     30   	return ReaderFunc(func(output []byte) (int, error) {
    31     31   		var (
    32     32   			readCount int
    33     33   			err       error
    34     34   		)

Modified src/0dev.org/ioutil/ioutil_test.go from [a857b5c640] to [f071d3739a].

    49     49   
    50     50   func TestBlockReader(t *testing.T) {
    51     51   	var (
    52     52   		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
    53     53   		output []byte = make([]byte, 16)
    54     54   
    55     55   		reader *bytes.Reader = bytes.NewReader(input)
    56         -		min    io.Reader     = BlockReader(reader, 4)
           56  +		min    io.Reader     = SizedReader(reader, 4)
    57     57   	)
    58     58   
    59     59   	// Expecting a read count of 2
    60     60   	count, err := min.Read(output[:2])
    61     61   	if count != 2 {
    62     62   		t.Error("Invalid read count from MinReader", count)
    63     63   	}
................................................................................
    80     80   		t.Error("Invalid read count from MinReader", count)
    81     81   	}
    82     82   	if err != nil {
    83     83   		t.Error("Unexpected error from MinReader", err)
    84     84   	}
    85     85   
    86     86   	// Expecting a read count of 0 with an EOF as the buffer should be empty
    87         -	count, err = min.Read(output[:4])
           87  +	count, err = min.Read(output[:1])
    88     88   	if count != 0 {
    89     89   		t.Error("Invalid read count from MinReader", count)
    90     90   	}
    91     91   	if err != io.EOF {
    92     92   		t.Error("Unexpected error from MinReader", err)
    93     93   	}
    94     94   }

Modified src/0dev.org/predictor/predictor.go from [625ed7e8bc] to [1bc0c5d728].

   117    117   
   118    118   // Returns an io.Reader implementation that wraps the provided io.Reader
   119    119   // and decompresses data according to the predictor algorithm
   120    120   func Decompressor(reader io.Reader) io.Reader {
   121    121   	var ctx context
   122    122   	ctx.input = make([]byte, 0, 8)
   123    123   
   124         -	return iou.BlockReader(iou.ReaderFunc(func(output []byte) (int, error) {
          124  +	return iou.SizedReader(iou.ReaderFunc(func(output []byte) (int, error) {
   125    125   		var (
   126    126   			err               error
   127    127   			flags, predicted  byte
   128    128   			rc, total, copied int
   129    129   		)
   130    130   
   131    131   		// Read the next prediction header