// Reads a file into a channel func readFileInto(into chan *[]byte) { f, err := os.Open(*inputFile) if err != nil { log.Fatal(err) } bf := bufio.NewReaderSize(f, 20000) for { line, isPrefix, err := bf.ReadLine() switch { case err == io.EOF: break case err != nil: log.Fatal(err) case isPrefix: log.Fatal("Error: Unexpected long line reading", f.Name()) } // Check the connection is still active if aliveStreams[into] != true { break } t := twitter.JSONtoTweet(line) j, err := twitter.TweetToJSON(t) if err != nil { log.Println(err) } j = append(j, []byte("\n")...) into <- &j } }
func fillOutgoingStreams(streams map[chan *[]byte]bool) { for { tweet := <-firehose for r := range streams { if len(r) == MAX_CHAN_LEN { <-r } json, _ := twitter.TweetToJSON(tweet) json = append(json, []byte("\n")...) r <- &json } } }