Fs.read_at.loop: def of mylsm-lsm-store@0.6.0.1 Import: import mylsm-lsm-store@0.6.0.1/src/Fs.bend as Fs Lines 282-318 of mylsm-lsm-store@0.6.0.1/src/Fs.bend: https://jend.leeeet.dev/read.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&start_line=282&end_line=318 import Base import bend-kit-bytes@0.3.2.0/bytes.bend as StorageBytes # Assembles a positional read from bounded chunks without moving the file cursor. def read_at.loop( fuel: Nat, state: ReadAtState ) -> IO( File & Result<&1, &1, U32 & String, StorageBytes.Bytes> ): match fuel: case 0n: read_at.exhausted(state) case 1n+rest: match state: case ReadAtNeed{file, +offset, +remaining, chunks}: match remaining: case 0n: read_at.finish(file, chunks) case 1n+_: do IO>: pair : File & Result<&1, &1, U32 & String, List<&2, U32>> <- File.read_at(file, U32.from_nat(offset), U32.from_nat(Nat.min(8192n, remaining))) read_at.loop(rest, ReadAtRead{pair, offset, remaining, chunks}) case ReadAtRead{pair, offset, +remaining, chunks}: match pair: case (file, Fail{error}): IO.pure(File & Result<&1, &1, U32 & String, StorageBytes.Bytes>, (file, Fail{error})) case (file, Done{Nil{}}): read_at.finish(file, chunks) case (file, Done{values}): read_at.loop(rest, ReadAtPacked{file, offset, remaining, chunks, read_at.pack(8192, values)}) case ReadAtPacked{file, offset, +remaining, chunks, buffer}: match buffer: case StorageBytes.Bytes{+len, buf}: read_at.loop(rest, ReadAtNeed{file, Nat.add(offset, U32.to_nat(len)), Nat.sub(remaining, U32.to_nat(len)), Con{StorageBytes.Bytes{len, buf}, chunks}}) Uses (22): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=File https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=File.read_at https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.pure https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.min https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.to_nat https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Bytes https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=ReadAtState https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=read_at.exhausted https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=read_at.finish https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=read_at.pack