source: code/trunk/vendor/github.com/yosssi/gcss/write.go@ 75

Last change on this file since 75 was 67, checked in by Izuru Yakumo, 23 months ago

Use vendored modules

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 948 bytes
Line 
1package gcss
2
3import (
4 "bufio"
5 "io"
6 "os"
7)
8
9// writeFlusher is the interface that groups the basic Write and Flush methods.
10type writeFlusher interface {
11 io.Writer
12 Flush() error
13}
14
15var newBufWriter = func(w io.Writer) writeFlusher {
16 return bufio.NewWriter(w)
17}
18
19// write writes the input byte data to the CSS file.
20func write(path string, bc <-chan []byte, berrc <-chan error) (<-chan struct{}, <-chan error) {
21 done := make(chan struct{})
22 errc := make(chan error)
23
24 go func() {
25 f, err := os.Create(path)
26
27 if err != nil {
28 errc <- err
29 return
30 }
31
32 defer f.Close()
33
34 w := newBufWriter(f)
35
36 for {
37 select {
38 case b, ok := <-bc:
39 if !ok {
40 if err := w.Flush(); err != nil {
41 errc <- err
42 return
43 }
44
45 done <- struct{}{}
46
47 return
48 }
49
50 if _, err := w.Write(b); err != nil {
51 errc <- err
52 return
53 }
54 case err := <-berrc:
55 errc <- err
56 return
57 }
58 }
59 }()
60
61 return done, errc
62}
Note: See TracBrowser for help on using the repository browser.