// HandleBytes will return a RespHandler that read the entire body of the request
// to a byte array in memory, would run the user supplied f function on the byte arra,
// and will replace the body of the original response with the resulting byte array.
166774
func HandleBytes(f func(b []byte, ctx *ProxyCtx) []byte) RespHandler {
	return FuncRespHandler(func(resp *http.Response, ctx *ProxyCtx) *http.Response {
		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			ctx.Warnf("Cannot read response %s", err)
			return resp
		}
		resp.Body.Close()

		resp.Body = ioutil.NopCloser(bytes.NewBuffer(f(b, ctx)))
		return resp
	})
}
1295841
func ParseBytes(s []byte, options ...Option) (*Token, error) {
	return Parse(bytes.NewReader(s), options...)
}
358544
func (r *buffer) ReadByte() (byte, error) {
	if r.off == r.size {
		return 0, io.EOF
	}
	b := r.data[r.off]
	r.off++
	return b, nil
}
864207
func (sh *Helper) GetBytes(key string) ([]byte, error) {
	if i, ok := sh.IndexMap[key]; ok {
		if i <= len(sh.submatch) {
			return sh.submatch[i], nil
		}
		return []byte{}, ErrIndexOutOfRange
	}
	return []byte{}, ErrNoSuchKey
}
1186934
func (u *UUID) ReadBytes(str []byte) error {
	/* NOTE: Duplicate of SetString, with different method signature, to
	   prevent unnecessary copying of memory due to string <-> []byte conversion */
	i := 0
	x := 0
	c := len(str)

	for x < c {
		a := hexchar2byte[str[x]]
		if a == 255 {
			// Invalid char, skip
			x++

			continue
		}

		// We need to perform this check after the attempted hex-read in case
		// we have trailing "}" characters
		if i >= 16 {
			return &ErrTooLong{x, i, c}
		}
		if x+1 >= c {
			// Not enough to scan
			return &ErrTooShort{x, i, c}
		}

		b := hexchar2byte[str[x+1]]
		if b == 255 {
			// Uneven hexadecimal byte
			return &ErrUneven{x, i, c}
		}

		u[i] = (a << 4) | b

		x += 2
		i++
	}

	if i != 16 {
		// Can only be too short here
		return &ErrTooShort{x, i, c}
	}

	return nil
}
1139962
func (t *Template) RenderBytes(context ...interface{}) ([]byte, error) {
	var b *bytes.Buffer
	err := t.Render(b, context...)
	return b.Bytes(), err
}
122119
func (h *HTTPBin) Bytes(w http.ResponseWriter, r *http.Request) {
	handleBytes(w, r, false)
}
1056434
func (b *Buffer) ReadBytes(p []byte) {
	copy(p, b.Consume(len(p)))
}
327375
func JSONBytes(w http.ResponseWriter, status int, b []byte) (err error) {

	w.Header().Set(ContentType, ApplicationJSONCharsetUTF8)
	w.WriteHeader(status)
	_, err = w.Write(b)
	return
}
672355
func (r *AnalyticsDeferredResultHandle) NextBytes() []byte {
	if r.err != nil {
		return nil
	}

	if r.status == "success" && r.decoder == nil {
		req := &gocbcore.HttpRequest{
			Service:  gocbcore.CbasService,
			Endpoint: r.handleUri,
			Method:   "GET",
		}

		resp, err := r.provider.DoHttpRequest(req)
		if err != nil {
			r.err = err
			return nil
		}
		if resp.StatusCode != 200 {
			r.err = fmt.Errorf("handle request failed, received http status %d", resp.StatusCode)
			return nil
		}

		r.decoder = json.NewDecoder(resp.Body)
		t, err := r.decoder.Token()
		if err != nil {
			bodyErr := resp.Body.Close()
			if bodyErr != nil {
				logDebugf("Failed to close response body, %s", bodyErr.Error())
			}
			r.err = err
			return nil
		}
		if delim, ok := t.(json.Delim); !ok || delim != '[' {
			bodyErr := resp.Body.Close()
			if bodyErr != nil {
				logDebugf("Failed to close response body, %s", bodyErr.Error())
			}
			r.err = errors.New("expected response opening token to be [ but was " + t.(string))
			return nil
		}

		r.stream = resp.Body
	} else if r.status != "success" {
		return nil
	}

	return r.nextBytes()
}
1007230
func readBytes(r io.Reader) ([]byte, error) {
	length, err := readInt32(r)
	if err != nil {
		return nil, err
	}
	buf := make([]byte, length)
	_, err = io.ReadFull(r, buf)
	if err != nil {
		return nil, err
	}
	return buf, nil
}
959074
func (a *API) getBytes(url string, params Params) ([]byte, error) {
	resp, err := try(a.client.Get(url, params, a.token))
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	return data, nil
}
666920
func (c Client) WithBytes(body []byte) Client {
	c.bytes = &body
	return c
}
147104
func (c *Cache) GetBytes(key string) (value []byte, ok bool) {
	v, ok := c.Get(key)
	if !ok {
		return nil, false
	}
	return v.([]byte), true
}
326189
func (b *SystemBackend) handleRawRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
	path := data.Get("path").(string)

	// Prevent access of protected paths
	for _, p := range protectedPaths {
		if strings.HasPrefix(path, p) {
			err := fmt.Sprintf("cannot read '%s'", path)
			return logical.ErrorResponse(err), logical.ErrInvalidRequest
		}
	}

	// Run additional checks if needed
	if err := checkRaw(b, path); err != nil {
		b.Core.logger.Warn(err.Error(), "path", path)
		return logical.ErrorResponse("cannot read '%s'", path), logical.ErrInvalidRequest
	}

	entry, err := b.Core.barrier.Get(ctx, path)
	if err != nil {
		return handleErrorNoReadOnlyForward(err)
	}
	if entry == nil {
		return nil, nil
	}

	// Run this through the decompression helper to see if it's been compressed.
	// If the input contained the compression canary, `outputBytes` will hold
	// the decompressed data. If the input was not compressed, then `outputBytes`
	// will be nil.
	outputBytes, _, err := compressutil.Decompress(entry.Value)
	if err != nil {
		return handleErrorNoReadOnlyForward(err)
	}

	// `outputBytes` is nil if the input is uncompressed. In that case set it to the original input.
	if outputBytes == nil {
		outputBytes = entry.Value
	}

	resp := &logical.Response{
		Data: map[string]interface{}{
			"value": string(outputBytes),
		},
	}
	return resp, nil
}
1096135
func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http.Request) {
	if !s.IsValid(w, r) {
		return
	}
	vars := mux.Vars(r)
	volume := vars[storageRESTVolume]
	filePath := vars[storageRESTFilePath]
	offset, err := strconv.Atoi(vars[storageRESTOffset])
	if err != nil {
		s.writeErrorResponse(w, err)
		return
	}
	length, err := strconv.Atoi(vars[storageRESTLength])
	if err != nil {
		s.writeErrorResponse(w, err)
		return
	}

	rc, err := s.storage.ReadFileStream(volume, filePath, int64(offset), int64(length))
	if err != nil {
		s.writeErrorResponse(w, err)
		return
	}
	defer rc.Close()
	w.Header().Set("Content-Length", strconv.Itoa(length))

	io.Copy(w, rc)
	w.(http.Flusher).Flush()
}
824689
func (b *Buffer) ReadByte() (c byte, err error) {
	if b.off >= len(b.buf) {
		// Buffer is empty, reset to recover space.
		b.Truncate(0)
		return 0, io.EOF
	}
	c = b.buf[b.off]
	b.off++
	return c, nil
}