// ReadFile reads the file `f` and parses its content to create
// a new Schema object
776818
func ReadFile(f string) (*Schema, error) {
	in, err := os.Open(f)
	if err != nil {
		return nil, err
	}
	defer in.Close()
	return Read(in)
}
354043
func (f *FilesystemIO) ReadFile(filename string) ([]byte, error) {
	return ioutil.ReadFile(filename)
}
1256872
func ReadFile(fs VFS, path string) ([]byte, error) {
	f, err := fs.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return ioutil.ReadAll(f)
}
665338
func ReadSchemas(file string) (Schemas, error) {
	config, err := configparser.Read(file)
	if err != nil {
		return Schemas{}, err
	}

	sections, err := config.AllSections()
	if err != nil {
		return Schemas{}, err
	}

	var schemas []Schema

	for i, sec := range sections {
		schema := Schema{}
		schema.Name = strings.Trim(strings.SplitN(sec.String(), "\n", 2)[0], " []")
		if schema.Name == "" || strings.HasPrefix(schema.Name, "#") {
			continue
		}

		if sec.ValueOf("pattern") == "" {
			return Schemas{}, fmt.Errorf("[%s]: empty pattern", schema.Name)
		}
		schema.Pattern, err = regexp.Compile(sec.ValueOf("pattern"))
		if err != nil {
			return Schemas{}, fmt.Errorf("[%s]: failed to parse pattern %q: %s", schema.Name, sec.ValueOf("pattern"), err.Error())
		}

		schema.Retentions, err = ParseRetentions(sec.ValueOf("retentions"))
		if err != nil {
			return Schemas{}, fmt.Errorf("[%s]: failed to parse retentions %q: %s", schema.Name, sec.ValueOf("retentions"), err.Error())
		}

		p := int64(0)
		if sec.ValueOf("priority") != "" {
			p, err = strconv.ParseInt(sec.ValueOf("priority"), 10, 0)
			if err != nil {
				return Schemas{}, fmt.Errorf("Failed to parse priority %q for [%s]: %s", sec.ValueOf("priority"), schema.Name, err)
			}
		}
		schema.Priority = int64(p)<<32 - int64(i) // to sort records with same priority by position in file

		reorderBufferStr := sec.ValueOf("reorderBuffer")
		if len(reorderBufferStr) > 0 {
			reorderWindow, err := strconv.ParseUint(reorderBufferStr, 10, 32)
			if err != nil {
				return Schemas{}, fmt.Errorf("[%s]: Failed to parse reorder buffer conf, expected a number: %s", schema.Name, reorderBufferStr)
			}

			// if reorderWindow == 0 we just disable the buffer
			if reorderWindow > 0 {
				schema.ReorderWindow = uint32(reorderWindow)
			}
		}

		schemas = append(schemas, schema)
	}

	sort.Sort(SchemaSlice(schemas))

	return NewSchemas(schemas), nil
}
482997
func (p *GSPath) ReadFile() ([]byte, error) {
	var b bytes.Buffer
	done, err := RetryWithBackoff(gcsReadBackoff, func() (bool, error) {
		b.Reset()
		_, err := p.WriteTo(&b)
		if err != nil {
			if os.IsNotExist(err) {
				// Not recoverable
				return true, err
			}
			return false, err
		}
		// Success!
		return true, nil
	})
	if err != nil {
		return nil, err
	} else if done {
		return b.Bytes(), nil
	} else {
		// Shouldn't happen - we always return a non-nil error with false
		return nil, wait.ErrWaitTimeout
	}
}
236085
func readCAFile(f string) ([]byte, error) {
	data, err := ioutil.ReadFile(f)
	if err != nil {
		return nil, fmt.Errorf("unable to load specified CA cert %s: %s", f, err)
	}
	return data, nil
}
370673
func (s *Script) ReadFromFile(file string) error {
	s.lock.Lock()
	defer s.lock.Unlock()
	b, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	s.body = strings.TrimSpace(string(b))
	return s.createSHA()
}
535783
func ReadIgnoreFile(filename string) ([]string, error) {
	igrd, err := os.Open(filename)
	if err != nil {
		//if os.IsNotExist(err){
		//    return []string{}, nil
		//}
		return nil, err
	}
	return ReadIgnore(igrd)
}
202248
func (r *realFS) ReadFile(name string) ([]byte, error) {
	return ioutil.ReadFile(name)
}
1030832
func readFile(f *os.File) (testOut []byte) {
	tmp := make([]byte, 256)
	for n, err := f.Read(tmp); err != io.EOF; n, err = f.Read(tmp) {
		testOut = append(testOut, tmp[:n]...)
	}
	return testOut
}
766456
func (f *FakeFS) ReadFile(name string) ([]byte, error) {
	buf, ok := f.Files[name]
	if !ok {
		return nil, FakeFileNotFound{Filename: name}
	}
	return buf.Bytes(), nil
}
381927
func (p *AssetPath) ReadFile() ([]byte, error) {
	data, err := Asset(p.location)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return nil, os.ErrNotExist
		}
	}
	return data, err
}
33317
func readFile(fs afero.Fs, filename string) (string, error) {
	if filename == "" {
		return "", errors.New("readFile needs a filename")
	}

	if info, err := fs.Stat(filename); err == nil {
		if info.Size() > 1000000 {
			return "", fmt.Errorf("file %q is too big", filename)
		}
	} else {
		return "", err
	}
	b, err := afero.ReadFile(fs, filename)

	if err != nil {
		return "", err
	}

	return string(b), nil
}
420981
func (bh *S3BackupHandle) ReadFile(ctx context.Context, filename string) (io.ReadCloser, error) {
	if !bh.readOnly {
		return nil, fmt.Errorf("ReadFile cannot be called on read-write backup")
	}
	object := objName(bh.dir, bh.name, filename)
	out, err := bh.client.GetObject(&s3.GetObjectInput{
		Bucket: bucket,
		Key:    object,
	})
	if err != nil {
		return nil, err
	}
	return out.Body, nil
}
825133
func ReadFile(filename string) ([]byte, error) {
	buf, err := ioutil_base.ReadFile(filename)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to read file %q", filename)
	}
	return buf, nil
}
803576
func ReadFile(ctx context.Context, fs FileSystem, path string) ([]byte, error) {
	rc, err := fs.Open(ctx, path)
	if err != nil {
		return nil, err
	}
	defer rc.Close()
	return ioutil.ReadAll(rc)
}
748944
func (c *VFSContext) ReadFile(location string) ([]byte, error) {
	if strings.Contains(location, "://") && !strings.HasPrefix(location, "file://") {
		// Handle our special case schemas
		u, err := url.Parse(location)
		if err != nil {
			return nil, fmt.Errorf("error parsing location %q - not a valid URI", location)
		}

		switch u.Scheme {
		case "metadata":
			switch u.Host {
			case "gce":
				httpURL := "http://169.254.169.254/computeMetadata/v1/instance/attributes/" + u.Path
				httpHeaders := make(map[string]string)
				httpHeaders["Metadata-Flavor"] = "Google"
				return c.readHttpLocation(httpURL, httpHeaders)
			case "aws":
				httpURL := "http://169.254.169.254/latest/" + u.Path
				return c.readHttpLocation(httpURL, nil)
			case "digitalocean":
				httpURL := "http://169.254.169.254/metadata/v1" + u.Path
				return c.readHttpLocation(httpURL, nil)

			default:
				return nil, fmt.Errorf("unknown metadata type: %q in %q", u.Host, location)
			}

		case "http", "https":
			return c.readHttpLocation(location, nil)
		}
	}

	location = strings.TrimPrefix(location, "file://")

	p, err := c.BuildVfsPath(location)
	if err != nil {
		return nil, err
	}
	return p.ReadFile()
}