Skip to content

Commit

Permalink
update solutions.pdf, compact the TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Mar 4, 2017
1 parent 5be3f3b commit d44114a
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ List of exercises and examples (x)
* [S08](https://github.com/miku/exploreio/tree/master/s08): Strings can be readers, io.ReadFull.
* [S09](https://github.com/miku/exploreio/tree/master/s09): Random reader and Base64 encoder.
* [S10](https://github.com/miku/exploreio/tree/master/s10): Prettify tabular data.
* [S11](https://github.com/miku/exploreio/tree/master/s11): Read a file, line by line.
* [S11](https://github.com/miku/exploreio/tree/master/s11): Read a file, line by line. (x)
* [S12](https://github.com/miku/exploreio/tree/master/s12): Read from multiple readers in turn.
* [S13](https://github.com/miku/exploreio/tree/master/s13): Write to more than one writer at once.
* [S14](https://github.com/miku/exploreio/tree/master/s14): Read into variables.
Expand Down
Binary file modified Solutions.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion s00/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
"os"
)

// TODO: Change a single character in this program so the complete file is read and printed.
// TODO: Change a single character in this program so the complete
// file is read and printed.
func main() {
file, err := os.Open("hello.txt")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions s01/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func main() {
log.Fatal(err)
}

// TODO: We don't need to loop manually, there is a helper function for that.
// TODO: Replace the next 10 lines with 5 that do the same.
// TODO: We don't need to loop manually, there is a helper
// function for that. Replace the next 10 lines
// with 5 lines that do the same.
var contents []byte
for {
b := make([]byte, 8)
Expand Down
3 changes: 2 additions & 1 deletion s02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func main() {
log.Fatal(err)
}

// TODO: Write contents of the file to the standard output, without using a byte slice (3 lines).
// TODO: Write contents of the file to the standard output,
// without using a byte slice (3 lines).
// ...
// ...
// ...
Expand Down
2 changes: 1 addition & 1 deletion s03/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package main

func main() {
// TODO: Read input from standard input and pass it to standard output,
// TODO: without using a byte slice (3 lines).
// without using a byte slice (3 lines).
// ...
// ...
// ...
Expand Down
6 changes: 4 additions & 2 deletions s04/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
package main

func main() {
// TODO: Read gzip compressed input from standard input and print it to standard output,
// TODO: without using a byte slice (7 lines).

// TODO: Read gzip compressed data from standard input and write
// to standard output, without using a byte slice (7 lines).
//
// ...
// ...
// ...
Expand Down
8 changes: 4 additions & 4 deletions s05/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
package main

import (
"image"
_ "image/gif" // register gif decoder
"image/jpeg"
_ "image/png" // register png decoder
"io"
"log"
Expand All @@ -24,8 +22,10 @@ import (

// toJPG converts a GIF or PNG image int JPEG.
func toJPG(r io.Reader, w io.Writer) error {
// TODO: Decode the image and encode it to JPEG, write it to the given writer (5 lines).
// TODO: Hint: Utilize methods taking io.Reader or io.Writer in https://golang.org/pkg/image/.
// TODO: Decode the image and encode it to JPEG, write it
// to the given writer (5 lines).
// Hint: Utilize methods taking io.Reader or io.Writer
// in https://golang.org/pkg/image/.
// ...
// ...
// ...
Expand Down
4 changes: 3 additions & 1 deletion s08/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ package main
import (
"fmt"
"io"
"log"
"strings"
)

func main() {
r := strings.NewReader(`Strings can be readers, too.`)
// TODO: Read the first 7 bytes of the string into a byte slice, then print to stdout (5 lines).
// TODO: Read the first 7 bytes of the string into a byte slice,
// then print to stdout (5 lines).
b := make([]byte, 7)
if _, err := io.ReadFull(r, b); err != nil {
log.Fatal(err)
Expand Down
5 changes: 2 additions & 3 deletions s10/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
package main

import (
"io"
"log"
"os"
"text/tabwriter"
)
Expand All @@ -21,7 +19,8 @@ func main() {
// https://golang.org/pkg/text/tabwriter/#NewWriter
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight|tabwriter.Debug)

// TODO: Read tabulated data from standard in and write it to the tabwriter (3 lines).
// TODO: Read tabulated data from standard in
// and write it to the tabwriter (3 lines).
// ...
// ...
// ...
Expand Down
5 changes: 2 additions & 3 deletions s12/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ package main

import (
"io"
"log"
"os"
"strings"
)

func main() {
// TODO: Read from these four readers and write to standard output (4 lines).
// TODO: Read from these four readers
// and write to standard output (4 lines).
rs := []io.Reader{
strings.NewReader("Hello\n"),
strings.NewReader("Gopher\n"),
Expand Down
3 changes: 2 additions & 1 deletion s14/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func main() {
f float64
s string
)
// TODO: Read an int, a float and a string from standard input (3 lines).
// TODO: Read an int, a float and a string from
// standard input (3 lines).
// ...
// ...
// ...
Expand Down
6 changes: 2 additions & 4 deletions s15/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ package main

import (
"bytes"
"fmt"
"io"
"log"
"os"
)

func main() {
var buf bytes.Buffer
if _, err := buf.WriteString("abc.xyz"); err != nil {
log.Fatal(err)
}
// TODO: Read one byte at a time from the buffer and print the hex value on stdout (10 lines).
// TODO: Read one byte at a time from the buffer
// and print the hex value on stdout (10 lines).
// ...
// ...
// ...
Expand Down
5 changes: 2 additions & 3 deletions s18b/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
package main

import (
"io"
"log"
"net"
"os"
)

func main() {
Expand All @@ -32,5 +30,6 @@ func main() {
log.Fatal(err)
}
defer conn.Close()
// TODO: Send a GET request, read the reponse and print it to standard output (6 lines).
// TODO: Send a GET request, read the reponse and print it
// to standard output (6 lines).
}
4 changes: 2 additions & 2 deletions s21/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package main

import (
"bytes"
"io"
"log"
"os"
Expand All @@ -16,7 +15,8 @@ type UpperReader struct {
r io.Reader
}

// TODO: Implement UpperReader, a reader that converts all Unicode letter mapped to their upper case (6 lines).
// TODO: Implement UpperReader, a reader that converts
// all Unicode letter mapped to their upper case (6 lines).
func (r *UpperReader) Read(p []byte) (n int, err error) {
// ...
// ...
Expand Down
3 changes: 2 additions & 1 deletion s22/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"os"
)

// TODO: Implement type Discard, which throws away everything that is written to it (4 lines).
// TODO: Implement type Discard, which throws away
// everything that is written to it (4 lines).
// ...

// ...
Expand Down
3 changes: 2 additions & 1 deletion s23/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"os"
)

// TODO: Implement UpperWriter, a reader that converts all Unicode letter mapped to their upper case (6 lines).
// TODO: Implement UpperWriter, a reader that converts
// all Unicode letter mapped to their upper case (6 lines).
// ...
// ...
// ...
Expand Down
8 changes: 5 additions & 3 deletions s24a/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"io/ioutil"
"log"
"os"
"sync/atomic"
)

// TODO: Implement a reader that counts the total number of bytes read (12 lines).
// TODO: It should have a Count() uint64 method, that returns the number of bytes read so far.
// TODO: Implement a reader that counts the total
// number of bytes read.
// It should have a Count() uint64 method,
// that returns the number of bytes read so far.
// (12 lines).
// ...
// ...
// ...
Expand Down
3 changes: 2 additions & 1 deletion s27b/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type TimeoutReader struct {
timeout time.Duration
}

// TODO: Implement a reader that times out after a certain a given timeout (21 lines).
// TODO: Implement a reader that times out after
// a certain a given timeout (21 lines).
// ...
// ...
// ...
Expand Down
2 changes: 1 addition & 1 deletion s41/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Can we read concurrently from a reader?
// S41: Can we read concurrently from a reader?
//
// $ go run main.go | head -10
// 0
Expand Down
2 changes: 1 addition & 1 deletion s43/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// S43: Like /dev/zero
// S43: Like /dev/zero.
//
// OUTPUT:
//
Expand Down

0 comments on commit d44114a

Please sign in to comment.