Golang bufio.Available() function example
package bufio
Available returns how many bytes are unused in the buffer.
Golang bufio.Available() 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()
fmt.Printf("Bytes available : %d\n", screenWriter.Available())
}
Output :
Bytes available : 8166
Bytes available : 8192
Advertisement
Something interesting
Tutorials
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+5.3k PHP : Hide PHP version information from curl
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+9k Golang : How to use Gorilla webtoolkit context package properly
+21.2k Golang : How to force compile or remove object files first before rebuild?
+80.6k Golang : How to return HTTP status code?
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+4.7k JavaScript: Add marker function on Google Map
+12.4k Golang : Search and extract certain XML data example
+9.3k Golang : Timeout example
+21.6k Golang : GORM create record or insert new record into database example