Skip to content

Commit c5a7a35

Browse files
committed
add comment about io.Reader and io.Writer
1 parent 78c2926 commit c5a7a35

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

kadai2/imura81gt/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
【TRY】io.Readerとio.Writer
2+
================================================================================
3+
4+
io.Readerとio.Writerについて調べてみよう
5+
6+
Q.標準パッケージでどのように使われているか
7+
--------------------------------------------------------------------------------
8+
9+
### io.Writer / io.Reader が実装されている package を探したい
10+
11+
Ref. https://ascii.jp/elem/000/001/243/1243667/#io.writerの実装状況利用状況を調べる
12+
13+
```
14+
GOPATH=/ godoc -http ":6060" -analysis type
15+
```
16+
17+
implements が見れるようになる。
18+
19+
io.Writer
20+
http://localhost:6060/pkg/io/#Writer
21+
22+
![docs/io_writer.png](docs/io_writer.png)
23+
24+
io.Reader
25+
http://localhost:6060/pkg/io/#Reader
26+
27+
![docs/io_reader.png](docs/io_reader.png)
28+
29+
30+
- file への読み書き
31+
- image への読み書き
32+
- 圧縮ファイル への読み書き
33+
- pipe への読み書き
34+
- buffer への読み書き
35+
- network通信への読み書き
36+
37+
等に使われている。
38+
39+
40+
41+
Q.io.Readerとio.Writerがあることで、どういう利点があるのか具体例を挙げて考えてみる
42+
--------------------------------------------------------------------------------
43+
44+
たとえば画像を扱うことを考えてみる。
45+
46+
画像を "どこに" 出力するのかを考えると色んなパターンがある。
47+
48+
- ブラウザ(html上に)出力する
49+
- 圧縮してブラウザ上に出力する
50+
- ファイルに出力する
51+
- 出力しない (/dev/nullに出力する)
52+
53+
image/png.decoder 等は出力先を意識せずに、io.Readerに準じた reader であれば処理を行えるから、便利。
54+
55+
56+
57+
【TRY】テストを書いてみよう
58+
================================================================================
59+
60+
1回目の宿題のテストを作ってみて下さい
61+
62+
- [ ] テストのしやすさを考えてリファクタリングしてみる
63+
- [ ] テストのカバレッジを取ってみる
64+
- [ ] テーブル駆動テストを行う
65+
- [ ] テストヘルパーを作ってみる
66+
67+
68+
69+
70+
71+

kadai2/imura81gt/docs/io_reader.png

467 KB
Loading

kadai2/imura81gt/docs/io_writer.png

527 KB
Loading

0 commit comments

Comments
 (0)