// CopyFromReader acquires a connection, delegates the call to that connection, and releases the connection
424879
func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (CommandTag, error) {
	c, err := p.Acquire()
	if err != nil {
		return "", err
	}
	defer p.Release(c)

	return c.CopyFromReader(r, sql)
}
782184
func AcquireReader(buf []byte, simple bool) *Reader {
	return defaultReaderPool.AcquireReader(buf, simple)
}
1233358
func (m *MultipartRequest) ReadFrom(r io.Reader) (int64, error) {
	n, err := encoding.ReadFrom(r, &m.Type, &m.Flags, &defaultPad4)
	if err != nil {
		return n, err
	}

	// Just copy the rest of the body to the request.
	buf := new(bytes.Buffer)
	m.Body = buf

	nn, err := io.Copy(buf, r)
	return n + nn, err
}
1236165
func LoadFromReader(reader io.Reader, password []byte) (*KeyStore, error) {
	ks := &KeyStore{
		entries: make(map[string]interface{}),
	}
	err := ks.Parse(reader, password)
	if err != nil {
		return nil, err
	}
	return ks, err
}
889979
func NewBlockFromReader(r io.Reader) (*Block, error) {
	// Deserialize the bytes into a MsgBlock.
	var msgBlock wire.MsgBlock
	err := msgBlock.Deserialize(r)
	if err != nil {
		return nil, err
	}

	b := Block{
		msgBlock:    &msgBlock,
		blockHeight: BlockHeightUnknown,
	}
	return &b, nil
}
1224704
func (s *RawString) ReadFrom(r Reader, l int) error {
	var ba RawByteSlice
	if err := ba.ReadFrom(r, l); err != nil {
		return err
	}
	*s = RawString(ba)

	return nil
}
944545
func LoadFrom(r io.Reader) error {
	envy.Load()
	deets, err := ParseConfig(r)
	if err != nil {
		return err
	}
	for n, d := range deets {
		con, err := NewConnection(d)
		if err != nil {
			log(logging.Warn, "unable to load connection %s: %v", n, err)
			continue
		}
		Connections[n] = con
	}
	return nil
}
739801
func (s *String) ReadFrom(r Reader, l int) error {
	var ba ByteSlice
	if err := ba.ReadFrom(r, l); err != nil {
		return err
	}
	*s = String(ba)

	return nil
}
54574
func newCompressingStoredFieldsReaderFrom(reader *CompressingStoredFieldsReader) *CompressingStoredFieldsReader {
	return &CompressingStoredFieldsReader{
		version:           reader.version,
		fieldInfos:        reader.fieldInfos,
		fieldsStream:      reader.fieldsStream.Clone(),
		indexReader:       reader.indexReader.Clone(),
		maxPointer:        reader.maxPointer,
		chunkSize:         reader.chunkSize,
		packedIntsVersion: reader.packedIntsVersion,
		compressionMode:   reader.compressionMode,
		decompressor:      reader.compressionMode.NewDecompressor(),
		numDocs:           reader.numDocs,
		bytes:             make([]byte, len(reader.bytes)),
		closed:            false,
	}
}
967156
func Copy(ctx context.Context, src io.Reader, dst io.Writer) (int64, error) {
	return io.Copy(dst, NewReader(ctx, src))
}
1103060
func SliceFromReader(r io.Reader) (Slice, error) {
	if r, ok := r.(*bufio.Reader); ok {
		// Buffered reader can use faster path.
		return sliceFromBufReader(r)
	}
	hdr := make(Slice, 1, maxByteSizeBytes)
	// Read first byte
	if err := readBytes(hdr, r); err != nil {
		if Cause(err) == io.EOF {
			// Empty slice
			return nil, nil
		}
		return nil, WithStack(err)
	}
	// Lookup first size
	// check if the type has a fixed length first
	l := fixedTypeLengths[hdr[0]]
	if l != 0 {
		// Found fixed length, read it (minus byte already read)
		s := make(Slice, l)
		s[0] = hdr[0]
		if err := readBytes(s[1:], r); err != nil {
			return nil, WithStack(err)
		}
		return s, nil
	}

	readRemaining := func(prefix Slice, l ValueLength) (Slice, error) {
		s := make(Slice, l)
		copy(s, prefix)
		if err := readBytes(s[len(prefix):], r); err != nil {
			return nil, WithStack(err)
		}
		return s, nil
	}

	// types with dynamic lengths need special treatment:
	h := hdr[0]
	switch hdr.Type() {
	case Array, Object:
		if h == 0x13 || h == 0x14 {
			// compact Array or Object
			l, bytes, err := readVariableValueLengthFromReader(r, false)
			if err != nil {
				return nil, WithStack(err)
			}
			return readRemaining(append(hdr, bytes...), l)
		}

		vpackAssert(h > 0x00 && h <= 0x0e)
		l, bytes, err := readIntegerNonEmptyFromReader(r, widthMap[h])
		if err != nil {
			return nil, WithStack(err)
		}
		return readRemaining(append(hdr, bytes...), ValueLength(l))

	case String:
		vpackAssert(h == 0xbf)

		// long UTF-8 String
		l, bytes, err := readIntegerFixedFromReader(r, 8)
		if err != nil {
			return nil, WithStack(err)
		}
		return readRemaining(append(hdr, bytes...), ValueLength(l+1+8))

	case Binary:
		vpackAssert(h >= 0xc0 && h <= 0xc7)
		x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xbf)
		if err != nil {
			return nil, WithStack(err)
		}
		l := ValueLength(1 + ValueLength(h) - 0xbf + ValueLength(x))
		return readRemaining(append(hdr, bytes...), l)

	case BCD:
		if h <= 0xcf {
			// positive BCD
			vpackAssert(h >= 0xc8 && h < 0xcf)
			x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xc7)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(1 + ValueLength(h) - 0xc7 + ValueLength(x))
			return readRemaining(append(hdr, bytes...), l)
		}

		// negative BCD
		vpackAssert(h >= 0xd0 && h < 0xd7)
		x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xcf)
		if err != nil {
			return nil, WithStack(err)
		}
		l := ValueLength(1 + ValueLength(h) - 0xcf + ValueLength(x))
		return readRemaining(append(hdr, bytes...), l)

	case Custom:
		vpackAssert(h >= 0xf4)
		switch h {
		case 0xf4, 0xf5, 0xf6:
			x, bytes, err := readIntegerFixedFromReader(r, 1)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(2 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xf7, 0xf8, 0xf9:
			x, bytes, err := readIntegerFixedFromReader(r, 2)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(3 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xfa, 0xfb, 0xfc:
			x, bytes, err := readIntegerFixedFromReader(r, 4)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(5 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xfd, 0xfe, 0xff:
			x, bytes, err := readIntegerFixedFromReader(r, 8)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(9 + x)
			return readRemaining(append(hdr, bytes...), l)
		}
	}

	return nil, WithStack(InternalError)
}
459655
func CopyMultipleReaders(readers []io.Reader, writer io.Writer) (inCounter int64, outCounter int64, e error) {

	writerChan := make(chan []byte, 16*len(readers))

	errChan := make(chan error, len(readers))
	defer close(errChan)

	var wg sync.WaitGroup
	for _, reader := range readers {
		wg.Add(1)
		go func(reader io.Reader) {
			defer wg.Done()
			err := ProcessMessage(reader, func(data []byte) error {
				writerChan <- data
				atomic.AddInt64(&inCounter, 1)
				return nil
			})
			errChan <- err
		}(reader)
	}
	wg.Add(1)
	go func() {
		defer wg.Done()
		for data := range writerChan {
			if err := WriteMessage(writer, data); err != nil {
				errChan <- fmt.Errorf("WriteMessage Error: %v", err)
				break
			}
			atomic.AddInt64(&outCounter, 1)
		}
	}()

	for range readers {
		err := <-errChan
		if err != nil && err != io.EOF {
			return inCounter, outCounter, err
		}
	}
	close(writerChan)

	wg.Wait()

	return inCounter, outCounter, nil
}
376884
func sliceFromBufReader(r *bufio.Reader) (Slice, error) {
	// ByteSize is always found within first 16 bytes
	hdr, err := r.Peek(maxByteSizeBytes)
	if len(hdr) == 0 && err != nil {
		if Cause(err) == io.EOF {
			// Empty slice
			return nil, nil
		}
		return nil, WithStack(err)
	}
	s := Slice(hdr)
	size, err := s.ByteSize()
	if err != nil {
		return nil, WithStack(err)
	}
	// Now that we know the size, read the entire slice
	buf := make(Slice, size)
	offset := 0
	bytesRead := 0
	for ValueLength(bytesRead) < size {
		n, err := r.Read(buf[offset:])
		bytesRead += n
		offset += n
		if err != nil && ValueLength(bytesRead) < size {
			return nil, WithStack(err)
		}
	}
	return buf, nil
}
403584
func (t *TablePropWildcards) ReadFrom(r io.Reader) (int64, error) {
	return readTablePropXM(r, &t.Fields, nil)
}
777192
func (client *Client) Copy(cid, resource string) (TarReader, error) {
	data, err := json.Marshal(map[string]string{"Resource": resource})
	if err != nil {
		return TarReader{}, err
	}

	uri := fmt.Sprintf("/containers/%s/copy", cid)

	resp, err := client.DoRequest("POST", uri, bytes.NewReader(data))
	if err != nil {
		return TarReader{}, err
	}
	return TarReader{
		tar.NewReader(resp.Body),
		resp.Body,
	}, nil
}
1225881
func (s *Chan) readFrom(mr Reader) {
	// single reader, no need for Mutex
	mr.(*reader).lock = new(nullLocker)

Loop:
	for {
		buf, err := mr.ReadMsg()
		if err != nil {
			if err == io.EOF {
				break Loop // done
			}

			// unexpected error. tell the client.
			s.ErrChan <- err
			break Loop
		}

		select {
		case <-s.CloseChan:
			break Loop // told we're done
		case s.MsgChan <- buf:
			// ok seems fine. send it away
		}
	}

	close(s.MsgChan)
	// signal we're done
	s.CloseChan <- true
}
914325
func (m *MockContainerAPIClient) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
	ret := m.ctrl.Call(m, "CopyFromContainer", ctx, container, srcPath)
	ret0, _ := ret[0].(io.ReadCloser)
	ret1, _ := ret[1].(types.ContainerPathStat)
	ret2, _ := ret[2].(error)
	return ret0, ret1, ret2
}