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
+9.7k Golang : Find correlation coefficient example
+9.3k Golang : Temperatures conversion example
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+7.5k Golang : How to handle file size larger than available memory panic issue
+14k Golang : Compress and decompress file with compress/flate example
+7.5k Golang : How to stop user from directly running an executable file?
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+5.9k Golang : Generate multiplication table from an integer example
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+21.2k Golang : Clean up null characters from input data
+7.1k Golang : Get environment variable