Standard library / net/http/httputil

httputil.NewChunkedReader()

Decode HTTP chunked-transfer framing into payload bytes until the zero-size chunk. Normal net/http automatically handles framing; this is a low-level format example. Expected stdout: 'abc\n'.

Formal Syntax & Structure

go syntaxgo
func NewChunkedReader(r io.Reader) io.Reader

Parameters & Attributes

NameTypeDescription
rio.ReaderBuffered reader or underlying stream as specified by its type; nil selects the default for legacy connections.

Return Value

io.Reader

Reader that returns decoded chunk payload bytes.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "net/http/httputil"  "strings")
func main() {  r := httputil.NewChunkedReader(strings.NewReader("3\r\nabc\r\n0\r\n\r\n"))  fmt.Println(string(must(io.ReadAll(r))))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference