Standard library / bufio
bufio.Reader.Discard()
Skips n bytes and returns the actual number discarded and any error. Negative n returns ErrNegativeCount. Expected stdout: '2 c <nil>\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Reader) Discard(n int) (discarded int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| n | int | Requested byte count or bound. |
Return Value
(discarded int, err error)
Skips n bytes and returns the actual number discarded and any error.
Working Example
Example Snippetgo
package main
import ( "bufio" "fmt" "strings")
func main() { r := bufio.NewReader(strings.NewReader("abc")) n, e := r.Discard(2) c, _ := r.ReadByte() fmt.Println(n, string(c), e)}