// read initializes the node from a page.
15796
func (n *node) read(p *page) {
	n.pgid = p.id
	n.isLeaf = ((p.flags & leafPageFlag) != 0)
	n.inodes = make(inodes, int(p.count))

	for i := 0; i < int(p.count); i++ {
		inode := &n.inodes[i]
		if n.isLeaf {
			elem := p.leafPageElement(uint16(i))
			inode.flags = elem.flags
			inode.key = elem.key()
			inode.value = elem.value()
		} else {
			elem := p.branchPageElement(uint16(i))
			inode.pgid = elem.pgid
			inode.key = elem.key()
		}
		_assert(len(inode.key) > 0, "read: zero-length inode key")
	}

	// Save first key so we can find the node in the parent when we spill.
	if len(n.inodes) > 0 {
		n.key = n.inodes[0].key
		_assert(len(n.key) > 0, "read: zero-length node key")
	} else {
		n.key = nil
	}
}
1315003
func Read(r io.Reader, opts ...Option) (Node, error) {
	opt := applyOptions(opts)
	s := new(scanner.Scanner)
	s = s.Init(r)
	s.Mode = scanner.ScanIdents | scanner.ScanFloats | scanner.ScanChars | scanner.ScanStrings
	if opt.supportComment {
		s.Mode |= scanner.ScanComments
	}
	p := new(parser)
	if err := p.init(s, opt); err != nil {
		return nil, err
	}
	return p.parseNode()
}
964092
func (r *Reader) Read(b []byte) (n int, err error) {
	if len(b) == 0 {
		return 0, nil
	}
	if r.pos >= len(r.buf) {
		return 0, io.EOF
	}
	n = copy(b, r.buf[r.pos:])
	r.pos += n
	return
}
715366
func (c *rwConn) Read(p []byte) (int, error) {
	return c.Reader.Read(p)
}
652608
func (u readCloser) Read(p []byte) (n int, err error) {
	return u.reader.Read(p)
}
1135189
func (r *Reader) Read(p []byte) (int, error) {
	if r.err != nil {
		return 0, r.err
	}
	for {
		if r.i < r.j {
			n := copy(p, r.decoded[r.i:r.j])
			r.i += n
			return n, nil
		}
		if !r.readFull(r.buf[:4]) {
			return 0, r.err
		}
		chunkType := r.buf[0]
		if !r.readHeader {
			if chunkType != chunkTypeStreamIdentifier {
				r.err = ErrCorrupt
				return 0, r.err
			}
			r.readHeader = true
		}
		chunkLen := int(r.buf[1]) | int(r.buf[2])<<8 | int(r.buf[3])<<16
		if chunkLen > len(r.buf) {
			r.err = ErrUnsupported
			return 0, r.err
		}

		// The chunk types are specified at
		// https://code.google.com/p/snappy/source/browse/trunk/framing_format.txt
		switch chunkType {
		case chunkTypeCompressedData:
			// Section 4.2. Compressed data (chunk type 0x00).
			/*
				if chunkLen < checksumSize {
					r.err = ErrCorrupt
					return 0, r.err
				}
			*/
			buf := r.buf[:chunkLen]
			if !r.readFull(buf) {
				return 0, r.err
			}
			/*
				checksum := uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24
				buf = buf[checksumSize:]
			*/
			n, err := DecodedLen(buf)
			if err != nil {
				r.err = err
				return 0, r.err
			}
			if n > len(r.decoded) {
				r.err = ErrCorrupt
				return 0, r.err
			}
			if _, err := Decode(r.decoded, buf); err != nil {
				r.err = err
				return 0, r.err
			}
			/*
				if crc(r.decoded[:n]) != checksum {
					r.err = ErrCorrupt
					return 0, r.err
				}
			*/
			r.i, r.j = 0, n
			continue

		case chunkTypeUncompressedData:
			// Section 4.3. Uncompressed data (chunk type 0x01).
			if chunkLen < checksumSize {
				r.err = ErrCorrupt
				return 0, r.err
			}
			buf := r.buf[:checksumSize]
			if !r.readFull(buf) {
				return 0, r.err
			}
			checksum := uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24
			// Read directly into r.decoded instead of via r.buf.
			n := chunkLen - checksumSize
			if !r.readFull(r.decoded[:n]) {
				return 0, r.err
			}
			if crc(r.decoded[:n]) != checksum {
				r.err = ErrCorrupt
				return 0, r.err
			}
			r.i, r.j = 0, n
			continue

		case chunkTypeStreamIdentifier:
			// Section 4.1. Stream identifier (chunk type 0xff).
			if chunkLen != len(magicBody) {
				r.err = ErrCorrupt
				return 0, r.err
			}
			if !r.readFull(r.buf[:len(magicBody)]) {
				return 0, r.err
			}
			for i := 0; i < len(magicBody); i++ {
				if r.buf[i] != magicBody[i] {
					r.err = ErrCorrupt
					return 0, r.err
				}
			}
			continue
		}

		if chunkType <= 0x7f {
			// Section 4.5. Reserved unskippable chunks (chunk types 0x02-0x7f).
			r.err = ErrUnsupported
			return 0, r.err

		} else {
			// Section 4.4 Padding (chunk type 0xfe).
			// Section 4.6. Reserved skippable chunks (chunk types 0x80-0xfd).
			if !r.readFull(r.buf[:chunkLen]) {
				return 0, r.err
			}
		}
	}
}
1230954
func Read(b []byte) (n int, err error) {
	return io.ReadFull(Reader, b)
}
255958
func (c *wsConn) Read(b []byte) (int, error) {
	n, err := c.reader.Read(b)
	if err != nil && err != io.EOF {
		return n, err
	} else if err == io.EOF {
		_, r, err := c.conn.NextReader()
		if err != nil {
			return 0, err
		}
		c.reader = r
	}

	return n, nil
}
2598
func (s *framedDecoderStream) Read(p []byte) (n int, err error) {

	if s.state == fdsHeader {
		err = s.loadHeader()
		if err != nil {
			return 0, err
		}
	}

	if s.state == fdsBody {
		n, err = s.r.Read(p)
		if err == ErrPunctuated {
			err = nil
			s.state = fdsFooter
		}
		if err == io.EOF {
			err = io.ErrUnexpectedEOF
		}
		if err != nil {
			return 0, err
		}
	}

	if s.state == fdsFooter {
		s.footer, err = s.r.ReadUntilPunctuation(s.frameLim)
		if err != nil {
			return 0, err
		}
		if s.frameChecker != nil {
			headerStr, err := s.toASCII(s.header)
			if err != nil {
				return 0, err
			}
			footerStr, err := s.toASCII(s.footer)
			if err != nil {
				return 0, err
			}
			if _, err = s.frameChecker(headerStr, footerStr); err != nil {
				return 0, err
			}
		}
		s.state = fdsEndOfStream
	}

	if s.state == fdsEndOfStream {
		err = s.consumeUntilEOF()
		if err == io.EOF && n > 0 {
			err = nil
		}
	}

	return n, err
}
225786
func (ch *Chunk) Read(p []byte) (n int, err error) {
	if ch == nil || ch.R == nil {
		return 0, errors.New("nil chunk/reader pointer")
	}
	n, err = ch.R.Read(p)
	ch.Pos += n
	return n, err
}
1104834
func (r *reader) Read(b []byte) (int, error) {
	r.Do(term.ClearAll)
	n, err := r.ReadCloser.Read(b)
	r.written += n
	r.p.ValueInt(r.written)
	r.render(term.CenterLine(r.p.String()))
	return n, err
}
330395
func (b *retryableRequestBody) Read(p []byte) (n int, err error) {
	return b.body.Read(p)
}
58936
func (ocfr *OCFReader) Read() (interface{}, error) {
	// NOTE: Test previous error before testing readReady to prevent overwriting
	// previous error.
	if ocfr.rerr != nil {
		return nil, ocfr.rerr
	}
	if !ocfr.readReady {
		ocfr.rerr = errors.New("Read called without successful Scan")
		return nil, ocfr.rerr
	}
	ocfr.readReady = false

	// decode one datum value from block
	var datum interface{}
	datum, ocfr.block, ocfr.rerr = ocfr.header.codec.NativeFromBinary(ocfr.block)
	if ocfr.rerr != nil {
		return false, ocfr.rerr
	}
	ocfr.remainingBlockItems--

	return datum, nil
}
1293610
func (c *Conn) Read(p []byte) (int, error) {
	return c.reader.Read(p)
}
914738
func (b *ByteBuf) Read(p []byte) (n int, err error) {
	if len(p) == 0 {
		return 0, nil
	}

	size := len(p)
	if len(p) > b.Readable() {
		size = b.Readable()
	}

	n = copy(p, b.buf[b.readerIndex:b.readerIndex+size])
	b.readerIndex += n
	return n, nil
}
894983
func (s *Stream) Read() error {
	if s.callback.IsValid() {
		return CanNotReadFromACallbackStream
	}
	if s.in == nil {
		return CanNotReadFromAnOutputOnlyStream
	}
	buf, frames, err := getBuffer(s.in, s.inParams)
	if err != nil {
		return err
	}
	return newError(C.Pa_ReadStream(s.paStream, buf, C.ulong(frames)))
}
1122286
func (r *LatinReader) Read(p []byte) (n int, err error) {

	var p2, utf8bytes []byte
	var n2 int
	var e2, e3 error

	p2 = make([]byte, len(p))
	n2, e2 = r.reader.Read(p2)

	if e2 == nil || e2 == io.EOF {

		utf8bytes, e3 = r.converter.Decode(p2[:n2])

		if e3 != nil {
			return 0, e3
		}

		r.buf.Write(utf8bytes) // n always len(input), error always nil

		return r.buf.Read(p)

	} else {
		copy(p, p2)
		n = n2
		err = e2
	}

	return
}