Golang net/textproto.Reader.ReadContinuedLine() and ReadContinuedLineBytes() functions example

package net/textproto

Golang net/textproto.Reader.ReadContinuedLine() function usage example

 package main

 import (
  "bufio"
  "bytes"
  "fmt"
  "net/textproto"
 )

 func main() {

  readbuffer := bytes.NewBuffer([]byte("Line 1 " +
 "continued... " +
 "Line 2"))

  reader := *bufio.NewReader(readbuffer)

  tpReader := textproto.NewReader(bufio.NewReader(&reader))

  //fmt.Println(&tpReader)

  str, err := tpReader.ReadContinuedLine()

  if err != nil {
 fmt.Println(err)
 return
  }

  fmt.Println("Whole line : ", str)

  //------------------------------------

  readbuffer2 := bytes.NewBuffer([]byte("Line 1 " +
 "continued... " +
 "Line 2"))

  reader2 := *bufio.NewReader(readbuffer2)

  tpReader2 := textproto.NewReader(bufio.NewReader(&reader2))

  strByte, err := tpReader2.ReadContinuedLineBytes()

  if err != nil {
 fmt.Println(err)
 return
  }

  fmt.Println("In []byte format : ", string(strByte[:]))

 }

Output :

Whole line : Line 1 continued... Line 2

In []byte format : Line 1 continued... Line 2

References :

http://golang.org/pkg/net/textproto/#Reader.ReadContinuedLine

http://golang.org/pkg/net/textproto/#Reader.ReadContinuedLineBytes

Advertisement