// Reads the content of the directory associated with the File.
// Returns an array of maximum num entries (if num is 0, returns
// all entries from the directory). If the operation fails, returns
// an Error.
551664
func (file *File) Readdir(num int) ([]*Dir, error) {
	buf := make([]byte, file.Fid.Clnt.Msize-IOHDRSZ)
	dirs := make([]*Dir, 32)
	pos := 0
	offset := file.offset
	defer func() {
		file.offset = offset
	}()
	for {
		n, err := file.Read(buf)
		if err != nil && err != io.EOF {
			return nil, err
		}

		if n == 0 {
			break
		}

		for b := buf[0:n]; len(b) > 0; {
			d, _, _, perr := UnpackDir(b, file.Fid.Clnt.Dotu)
			if perr != nil {
				// If we have unpacked anything, it is almost certainly
				// a too-short buffer. So return what we got.
				if pos > 0 {
					return dirs[0:pos], nil
				}
				return nil, perr
			}

			b = b[d.Size+2:]
			offset += uint64(d.Size + 2)
			if pos >= len(dirs) {
				s := make([]*Dir, len(dirs)+32)
				copy(s, dirs)
				dirs = s
			}

			dirs[pos] = d
			pos++
			if num != 0 && pos >= num {
				break
			}
		}
	}

	return dirs[0:pos], nil
}
668734
func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
	path = FixSlashes(path)
	files := make([]os.FileInfo, 0)
	skipSelf := true
	parse := func(resp interface{}) error {
		r := resp.(*response)

		if skipSelf {
			skipSelf = false
			if p := getProps(r, "200"); p != nil && p.Type.Local == "collection" {
				r.Props = nil
				return nil
			}
			return newPathError("ReadDir", path, 405)
		}

		if p := getProps(r, "200"); p != nil {
			f := new(File)
			if ps, err := url.QueryUnescape(r.Href); err == nil {
				f.name = pathpkg.Base(ps)
			} else {
				f.name = p.Name
			}
			f.path = path + f.name
			f.modified = parseModified(&p.Modified)
			f.etag = p.ETag
			f.contentType = p.ContentType

			if p.Type.Local == "collection" {
				f.path += "/"
				f.size = 0
				f.isdir = true
			} else {
				f.size = parseInt64(&p.Size)
				f.isdir = false
			}

			files = append(files, *f)
		}

		r.Props = nil
		return nil
	}

	err := c.propfind(path, false,
		`<d:propfind xmlns:d='DAV:'>
			<d:prop>
				<d:displayname/>
				<d:resourcetype/>
				<d:getcontentlength/>
				<d:getcontenttype/>
				<d:getetag/>
				<d:getlastmodified/>
			</d:prop>
		</d:propfind>`,
		&response{},
		parse)

	if err != nil {
		if _, ok := err.(*os.PathError); !ok {
			err = newPathErrorErr("ReadDir", path, err)
		}
	}
	return files, err
}
887569
func readDir(dirname string) (fi []os.FileInfo, err error) {
	f, err := os.Open(dirname)
	if err == nil {
		defer f.Close()
		if fi, err = f.Readdir(-1); fi != nil {
			sort.Sort(byName(fi))
		}
	}

	return
}
743754
func (f *Lucene46SegmentInfoFormat) Read(dir store.Directory,
	segName string, ctx store.IOContext) (si *SegmentInfo, err error) {

	filename := util.SegmentFileName(segName, "", SI_EXTENSION)
	var input store.ChecksumIndexInput
	if input, err = dir.OpenChecksumInput(filename, ctx); err != nil {
		return
	}

	var success = false
	defer func() {
		if !success {
			util.CloseWhileSuppressingError(input)
		} else {
			err = input.Close()
		}
	}()

	var codecVersion int
	if codecVersion, err = asInt(codec.CheckHeader(input, SI_CODEC_NAME, SI_VERSION_START, SI_VERSION_CURRENT)); err != nil {
		return
	}
	var versionStr string
	if versionStr, err = input.ReadString(); err != nil {
		return
	}
	var version util.Version
	if version, err = util.ParseVersion(versionStr); err != nil {
		err = errors.New(fmt.Sprintf("unable to parse version string (resource=%v): %v", input, err))
		return
	}
	var docCount int
	if docCount, err = asInt(input.ReadInt()); err != nil {
		return
	} else if docCount < 0 {
		return nil, errors.New(fmt.Sprintf("invalid docCount: %v (resource=%v)", docCount, input))
	}
	var b byte
	if b, err = input.ReadByte(); err != nil {
		return
	}
	var isCompoundFile = b == YES
	var diagnostics map[string]string
	if diagnostics, err = input.ReadStringStringMap(); err != nil {
		return
	}
	var files map[string]bool
	if files, err = input.ReadStringSet(); err != nil {
		return
	}

	if codecVersion >= SI_VERSION_CHECKSUM {
		_, err = codec.CheckFooter(input)
	} else {
		err = codec.CheckEOF(input)
	}
	if err != nil {
		return
	}

	si = NewSegmentInfo(dir, version, segName, docCount, isCompoundFile, nil, diagnostics)
	si.SetFiles(files)

	success = true
	return si, nil
}
902583
func getInputFiles(inputDir string) (res []string, err error) {
	files, err := ioutil.ReadDir(inputDir)
	if err != nil {
		return nil, fmt.Errorf("reading directory %s failed: %v", inputDir, err)
	}
	for _, f := range files {
		if strings.HasSuffix(f.Name(), inputFileExt) {
			res = append(res, filepath.Join(inputDir, f.Name()))
		}
	}
	return res, nil
}
921139
func (dr *DirReader) Readdir(ctx context.Context, n int) (entries []DirectoryEntry, err error) {
	sts, err := dr.StaticSet(ctx)
	if err != nil {
		return nil, fmt.Errorf("schema/dirreader: can't get StaticSet: %v", err)
	}
	up := dr.current + n
	if n <= 0 {
		dr.current = 0
		up = len(sts)
	} else {
		if n > (len(sts) - dr.current) {
			err = io.EOF
			up = len(sts)
		}
	}

	// TODO(bradfitz): push down information to the fetcher
	// (e.g. cachingfetcher -> remote client http) that we're
	// going to load a bunch, so the HTTP client (if not using
	// SPDY) can do discovery and see if the server supports a
	// batch handler, then get them all in one round-trip, rather
	// than attacking the server with hundreds of parallel TLS
	// setups.

	type res struct {
		ent DirectoryEntry
		err error
	}
	var cs []chan res

	// Kick off all directory entry loads.
	gate := syncutil.NewGate(20) // Limit IO concurrency
	for _, entRef := range sts[dr.current:up] {
		c := make(chan res, 1)
		cs = append(cs, c)
		gate.Start()
		go func(entRef blob.Ref) {
			defer gate.Done()
			entry, err := NewDirectoryEntryFromBlobRef(ctx, dr.fetcher, entRef)
			c <- res{entry, err}
		}(entRef)
	}

	for _, c := range cs {
		res := <-c
		if res.err != nil {
			return nil, fmt.Errorf("schema/dirreader: can't create dirEntry: %v", res.err)
		}
		entries = append(entries, res.ent)
	}
	return entries, nil
}
960607
func (d *Dir) ReadFile(subPath string) ([]byte, error) {
	node, err := d.GetByPath(subPath)
	if err != nil {
		return nil, err
	}
	if node.IsDir() {
		return nil, fmt.Errorf("Use ReadFile on directory ")
	}
	var fileNode = node.(*File)
	return fileNode.GetData(), nil
}
712893
func readDirPaths(fs http.FileSystem, dirname string) ([]string, error) {
	fis, err := vfsutil.ReadDir(fs, dirname)
	if err != nil {
		return nil, err
	}
	paths := make([]string, len(fis))
	for i := range fis {
		paths[i] = pathpkg.Join(dirname, fis[i].Name())
	}
	sort.Strings(paths)
	return paths, nil
}
434153
func (sfr *sparseFileReader) Read(b []byte) (n int, err error) {
	// Skip past all empty fragments.
	for len(sfr.sp) > 0 && sfr.sp[0].numBytes == 0 {
		sfr.sp = sfr.sp[1:]
	}

	// If there are no more fragments, then it is possible that there
	// is one last sparse hole.
	if len(sfr.sp) == 0 {
		// This behavior matches the BSD tar utility.
		// However, GNU tar stops returning data even if sfr.total is unmet.
		if sfr.pos < sfr.total {
			return sfr.readHole(b, sfr.total), nil
		}
		return 0, io.EOF
	}

	// In front of a data fragment, so read a hole.
	if sfr.pos < sfr.sp[0].offset {
		return sfr.readHole(b, sfr.sp[0].offset), nil
	}

	// In a data fragment, so read from it.
	// This math is overflow free since we verify that offset and numBytes can
	// be safely added when creating the sparseFileReader.
	endPos := sfr.sp[0].offset + sfr.sp[0].numBytes // End offset of fragment
	bytesLeft := endPos - sfr.pos                   // Bytes left in fragment
	if int64(len(b)) > bytesLeft {
		b = b[:bytesLeft]
	}

	n, err = sfr.rfr.Read(b)
	sfr.pos += int64(n)
	if err == io.EOF {
		if sfr.pos < endPos {
			err = io.ErrUnexpectedEOF // There was supposed to be more data
		} else if sfr.pos < sfr.total {
			err = nil // There is still an implicit sparse hole at the end
		}
	}

	if sfr.pos == endPos {
		sfr.sp = sfr.sp[1:] // We are done with this fragment, so pop it
	}
	return n, err
}
1052008
func (fs OsFS) ReadDir(path string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(path)
}
75519
func MaxByDir(a, b int, dir Direction) int {
	if dir == POSITIVE {
		return b
	}

	return a
}
1085334
func (DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(dirname)
}
795180
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
	// this disables directory listing
	return nil, nil
}
576406
func (fs *Filespace) ReadDir(subPath string) ([]os.FileInfo, error) {
	return ioutil.ReadDir(fs.path + subPath)
}
1117753
func (f *File) Read() (io.ReadSeeker, error) {
	if f.HasPermission(roles.Read) {
		return os.Open(f.FilePath)
	}
	return nil, roles.ErrPermissionDenied
}
1130601
func loadFileContent(v string) ([]byte, error) {
	filename, err := homedir.Expand(v)
	if err != nil {
		return nil, err
	}
	fileContent, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	return fileContent, nil
}
1216378
func (f *File) ReadContent() error {
	if len(f.Content) == 0 {
		content, err := ioutil.ReadFile(path.Join(f.Path, f.FileName))
		if err != nil {
			return err
		}
		f.Content = content
	}
	return nil
}