rando...@gmail.com
unread,Mar 28, 2012, 6:09:30 AM3/28/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Basically I would like to know if there is any way to skip the conversion at below line 19, marked with the comment "### question ###"
package main
import "fmt"
import "io"
import "log"
import "os"
func main() {
fr, err := os.Open("orig.txt")
if err != nil {
log.Fatalln(err)
}
fws, err := createFiles()
if err != nil {
log.Fatalln(err)
}
defer closeFiles(fws)
ws := make([]io.Writer, len(fws))
// ### question ### Is it possible to skip this step?
for i := 0; i < len(fws); i++ {
ws[i] = fws[i]
}
err = doStuff(fr, ws)
if err != nil {
log.Fatalln(err)
}
}
func doStuff(r io.Reader, ws []io.Writer) (err error) {
// Split the contents of r into the different io.Writers based on an
// algorithm that has no implication for this example. Below is a
// placeholder.
for _, w := range ws {
_, err = io.CopyN(w, r, 1)
if err != nil {
return err
}
}
return nil
}
func createFiles() (fws []*os.File, err error) {
for i := 0; i < 10; i++ {
f, err := os.Create(fmt.Sprintf("file_%04d.txt", i))
if err != nil {
return nil, err
}
fws = append(fws, f)
}
return fws, nil
}
func closeFiles(fws []*os.File) {
for _, f := range fws {
f.Close()
}
}
cheers /u