Golang Bufio writer .Flush() does not write small data when big buffer size (example 4096(standard size)*2)
package main
import (
"log"
"os"
"bufio"
)
func main() {
file, err := os.Create("test")
defer file.Close()
w := bufio.NewWriter(file)
w = bufio.NewWriterSize(
w,
4096*2,
)
bytesAvailable := w.Available()
log.Printf("Available %v
", bytesAvailable)
bw, _ := w.Write(
[]byte("A"),
)
log.Printf("written bytes: %v
", bw)
bytesAvailable = w.Available()
log.Printf("Available: %v
", bytesAvailable)
buf := w.Buffered()
log.Printf("buffered: %d
", buf)
err = w.Flush()
if err != nil {
log.Fatal(err)
}
}
When I use the standard size or I write more data it works as expected.