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
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+6.1k Golang : How to write backslash in string?
+11.7k Golang : Gorilla web tool kit secure cookie example
+37.5k Upload multiple files with Go
+19.3k Golang : Calculate entire request body length during run time
+13.5k Facebook PHP getUser() returns 0
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+14.1k Javascript : Prompt confirmation before exit
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations