Mercurial > yakumo_izuru > aya
view vendor/github.com/yosssi/gcss/write.go @ 74:d8727551f403 draft
The Empress (III)
* Change the way how versions are handled in version.go (to ease `go
install`)
* Upgrade yaml.v2 to yaml.v3
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Mon, 04 Dec 2023 00:54:29 +0000 |
parents | 787b5ee0289d |
children |
line wrap: on
line source
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 }