Golang bytes.Buffer.Next() function example
package bytes
Next returns a slice containing the next n (1st parameter) bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
Golang bytes.Buffer.Next() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBufferString("abcdefghi")
var threebytes [3]byte
buff.Read(threebytes[0:3])
fmt.Printf("%s\n", string(threebytes[:]))
// read the next 5 bytes
fmt.Printf("%s\n", string(buff.Next(5)))
}
Output :
abc
defgh
Reference :
Advertisement
Something interesting
Tutorials
+14k Golang : Compress and decompress file with compress/flate example
+28k Golang : Move file to another directory
+6.9k Golang : Calculate BMI and risk category
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+8.1k Golang : Variadic function arguments sanity check example
+32.2k Golang : Convert []string to []byte examples
+39k Golang : How to iterate over a []string(array)
+4.9k HTTP common errors and their meaning explained
+15.8k Golang : How to login and logout with JWT example
+13.9k Golang : How to check if a file is hidden?
+10.1k Golang : Compare files modify date example
+21.8k Golang : Convert string slice to struct and access with reflect example