package vfs

import "gitlink.org.cn/cloudream/jcs-pub/client/internal/mount/fuse"

type FuseDirReader struct {
	allEntries    []fuse.FsEntry
	nextReadIndex int
}

func newFuseDirReader(entries []fuse.FsEntry) *FuseDirReader {
	return &FuseDirReader{
		allEntries:    entries,
		nextReadIndex: 0,
	}
}

func (r *FuseDirReader) HasNext() bool {
	return r.nextReadIndex < len(r.allEntries)
}

func (r *FuseDirReader) Next(n int) ([]fuse.FsEntry, error) {
	if r.nextReadIndex >= len(r.allEntries) {
		return nil, nil
	}
	if n > len(r.allEntries)-r.nextReadIndex {
		n = len(r.allEntries) - r.nextReadIndex
	}
	entries := make([]fuse.FsEntry, n)
	for i := 0; i < n; i++ {
		entries[i] = r.allEntries[r.nextReadIndex+i]
	}
	r.nextReadIndex += n
	return entries, nil
}

func (r *FuseDirReader) Close() {

}
