Golang bufio.Flush() function example
package bufio
Flush writes any buffered data to the underlying io.Writer.
Golang bufio.Flush() function usage example
package main
import (
"bufio"
"fmt"
"bytes"
)
func main() {
screenBuffer := bytes.NewBuffer(nil)
screenWriter := bufio.NewWriterSize(screenBuffer, 8192) // 8192 = 8KB
// these two lines will take up 26 bytes from screenWriter
fmt.Fprint(screenWriter, "Hello, ")
fmt.Fprint(screenWriter, "world! 你好世界")
// print the initial size buffer ...
fmt.Printf("Bytes available : %d\n", screenWriter.Available())
// flush the buffer and free up the 26 bytes
screenWriter.Flush() // <--------------- flush is important! just like flushing your toilet
fmt.Printf("Bytes available : %d\n", screenWriter.Available())
}
Advertisement
Something interesting
Tutorials
+12.7k Golang : Sort and reverse sort a slice of bytes
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+16.3k Golang : convert string or integer to big.Int type
+9.7k Golang : Find correlation coefficient example
+5.2k Golang : Convert lines of string into list for delete and insert operation
+16k Golang : Get sub string example
+13.8k Golang : Gin framework accept query string by post request example
+23k Golang : Calculate time different
+11.2k Google Maps URL parameters configuration
+13.3k Golang : Date and Time formatting