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
+4.9k JQuery : Calling a function inside Jquery(document) block
+8.5k Linux/Unix : fatal: the Postfix mail system is already running
+37.5k Golang : Converting a negative number to positive number
+17k Golang : How to save log messages to file?
+16.3k Golang : Find out mime type from bytes in buffer
+9.6k Golang : Quadratic example
+8.1k Golang : Multiplexer with net/http and map
+6.3k Javascript : Generate random key with specific length
+26.8k Golang : Convert file content into array of bytes
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+7.8k Golang : Load DSA public key from file example
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter