Use vendored modules
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/aya/trunk@67 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
62
vendor/github.com/yosssi/gcss/write.go
generated
vendored
Normal file
62
vendor/github.com/yosssi/gcss/write.go
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
package gcss
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// writeFlusher is the interface that groups the basic Write and Flush methods.
|
||||
type writeFlusher interface {
|
||||
io.Writer
|
||||
Flush() error
|
||||
}
|
||||
|
||||
var newBufWriter = func(w io.Writer) writeFlusher {
|
||||
return bufio.NewWriter(w)
|
||||
}
|
||||
|
||||
// write writes the input byte data to the CSS file.
|
||||
func write(path string, bc <-chan []byte, berrc <-chan error) (<-chan struct{}, <-chan error) {
|
||||
done := make(chan struct{})
|
||||
errc := make(chan error)
|
||||
|
||||
go func() {
|
||||
f, err := os.Create(path)
|
||||
|
||||
if err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
w := newBufWriter(f)
|
||||
|
||||
for {
|
||||
select {
|
||||
case b, ok := <-bc:
|
||||
if !ok {
|
||||
if err := w.Flush(); err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
||||
done <- struct{}{}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := w.Write(b); err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
case err := <-berrc:
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return done, errc
|
||||
}
|
||||
Reference in New Issue
Block a user