file-misc.go 582 B

1234567891011121314151617181920
  1. package storage
  2. import (
  3. "github.com/anacrolix/torrent/segments"
  4. )
  5. // Returns the minimum file lengths required for the given extent to exist on disk. Returns false if
  6. // the extent is not covered by the files in the index.
  7. func minFileLengthsForTorrentExtent(
  8. fileSegmentsIndex segments.Index,
  9. off, n int64,
  10. each func(fileIndex int, length int64) bool,
  11. ) bool {
  12. return fileSegmentsIndex.Locate(segments.Extent{
  13. Start: off,
  14. Length: n,
  15. }, func(fileIndex int, segmentBounds segments.Extent) bool {
  16. return each(fileIndex, segmentBounds.Start+segmentBounds.Length)
  17. })
  18. }