Check-in [2bcd5307ea]
Overview
Comment:Added package ioutil with io.Writer and io.Reader function wrappers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2bcd5307ea2611963e6cc816d899979d0980b1dd
User & Date: spaskalev on 2014-12-23 07:52:13
Other Links: manifest | tags
Context
2014-12-23
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
2014-12-22
19:52
Added documentation for the decompressor check-in: 89bfe97384 user: spaskalev tags: trunk
Changes

Added src/0dev.org/ioutil/ioutil.go version [404db9969d].





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Package ioutil contains various constructs for io operations
package ioutil

// An function alias type that implements io.Writer
type WriterFunc func([]byte) (int, error)

// Delegates the call to the WriterFunc while implementing io.Writer
func (w WriterFunc) Write(b []byte) (int, error) {
	return w(b)
}

// An function alias type that implements io.Reader
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)
}

Added src/0dev.org/ioutil/ioutil_test.go version [e21bc31120].































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ioutil

import (
	diff "0dev.org/diff"
	"bytes"
	"testing"
)

func TestWriter(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte

		reader *bytes.Reader = bytes.NewReader(input)
		buffer bytes.Buffer
	)

	reader.WriteTo(WriterFunc(buffer.Write))
	output = buffer.Bytes()

	// Diff the result against the initial input
	delta := diff.Diff(diff.D{len(input), len(output),
		func(i, j int) bool { return input[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}

func TestReader(t *testing.T) {
	var (
		input  []byte = []byte{0, 1, 2, 3, 4, 5, 6, 7}
		output []byte

		reader *bytes.Reader = bytes.NewReader(input)
		buffer bytes.Buffer
	)

	buffer.ReadFrom(ReaderFunc(reader.Read))
	output = buffer.Bytes()

	// Diff the result against the initial input
	delta := diff.Diff(diff.D{len(input), len(output),
		func(i, j int) bool { return input[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}