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
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+12.8k Golang : http.Get example
+4.7k JavaScript: Add marker function on Google Map
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+5.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+5.2k Golang : Convert lines of string into list for delete and insert operation
+8.3k Golang : Auto-generate reply email with text/template package
+15.7k Golang : Get checkbox or extract multipart form data value example
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+12.5k Golang : HTTP response JSON encoded data
+6.7k Golang : Check if password length meet the requirement