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
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+21.6k Golang : Encrypt and decrypt data with TripleDES
+4.7k Linux/MacOSX : How to symlink a file?
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+5.3k PHP : Hide PHP version information from curl
+25.7k Golang : How to write CSV data to file
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+41.2k Golang : How to count duplicate items in slice/array?
+5.2k Responsive Google Adsense
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?