func (stream *Stream) Write(p []byte) (nn int, err error) {
	for len(p) > stream.Available() && stream.Error == nil {
		if stream.out == nil {
			stream.growAtLeast(len(p))
		} else {
			var n int
			if stream.Buffered() == 0 {
				n, stream.Error = stream.out.Write(p)
			} else {
				n = copy(stream.buf[stream.n:], p)
				stream.n += n
				stream.Flush()
			}
			nn += n
			p = p[n:]
		}
	}
	if stream.Error != nil {
		return nn, stream.Error
	}
	n := copy(stream.buf[stream.n:], p)
	stream.n += n
	nn += n
	return nn, nil
}
Write writes the contents of p into the buffer.
It returns the number of bytes written.
If nn < len(p), it also returns an error explaining
why the write is short.
package jsoniter
import (
	"io"
)
type Stream struct {
	cfg        *frozenConfig
	out        io.Writer
	buf        []byte
	n          int
	Error      error
	indention  int
	Attachment interface{}  
}
func NewStream(cfg API, out io.Writer, bufSize int) *Stream {
	return &Stream{
		cfg:       cfg.(*frozenConfig),
		out:       out,
		buf:       make([]byte, bufSize),
		n:         0,
		Error:     nil,
		indention: 0,
	}
}
func (stream *Stream) Pool() StreamPool {
	return stream.cfg
}
func (stream *Stream) Reset(out io.Writer) {
	stream.out = out
	stream.n = 0
}
func (stream *Stream) Available() int {
	return len(stream.buf) - stream.n
}
func (stream *Stream) Buffered() int {
	return stream.n
}
func (stream *Stream) Buffer() []byte {
	return stream.buf[:stream.n]
}