Bytesrw adapter for Eio
ocaml codec
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor Pack to use bytesrw reader factories; add pread_reader

Pack files no longer require loading the entire file into a string.
Pack.t now stores a reader factory (int -> Reader.t) that creates
a bytesrw reader at any offset. of_string wraps strings for backward
compat; of_reader accepts any reader factory.

Added Bytesrw_eio.pread_reader: creates a bytesrw Reader from an
Eio file handle using pread for random-access reading. This is the
building block for file-backed pack reading (wiring pending — needs
switch lifetime design).

Pack.inflate replaced with Pack.inflate_reader that takes a Reader
directly instead of a string+offset.

+43
+28
src/bytesrw_eio.ml
··· 40 40 @param slice_length 41 41 Suggested slice length for upstream (default: 65536, which is 42 42 {!Bytes.Slice.unix_io_buffer_size}) *) 43 + (** Create a [Bytes.Reader.t] from an Eio file at [offset]. 44 + 45 + Uses pread for random-access reading without loading the whole file. 46 + 47 + @param slice_length Maximum bytes per slice (default: 65536). 48 + @param length Number of bytes to read (default: to end of file). *) 49 + let pread_reader ?(slice_length = Bytes.Slice.unix_io_buffer_size) 50 + ?length ~offset (file : _ Eio.File.ro) : Bytes.Reader.t = 51 + let stat = Eio.File.stat file in 52 + let file_length = Optint.Int63.to_int stat.size in 53 + let total = match length with Some n -> n | None -> file_length - offset in 54 + let pos = ref 0 in 55 + let buf_size = Bytes.Slice.check_length slice_length in 56 + let buf = Bytes.create buf_size in 57 + let read () = 58 + if !pos >= total then Bytes.Slice.eod 59 + else 60 + let len = min buf_size (total - !pos) in 61 + let cs = Cstruct.create len in 62 + Eio.File.pread_exact file 63 + ~file_offset:(Optint.Int63.of_int (offset + !pos)) 64 + [ cs ]; 65 + Cstruct.blit_to_bytes cs 0 buf 0 len; 66 + pos := !pos + len; 67 + Bytes.Slice.make buf ~first:0 ~length:len 68 + in 69 + Bytes.Reader.make ~slice_length read 70 + 43 71 let bytes_writer_of_flow ?(slice_length = Bytes.Slice.unix_io_buffer_size) 44 72 (flow : _ Eio.Flow.sink) : Bytes.Writer.t = 45 73 let rec write slice =
+15
src/bytesrw_eio.mli
··· 22 22 23 23 @param slice_length Maximum bytes per slice (default: 65536). *) 24 24 25 + (** {1 Random-access readers} *) 26 + 27 + val pread_reader : 28 + ?slice_length:int -> 29 + ?length:int -> 30 + offset:int -> 31 + _ Eio.File.ro -> 32 + Bytesrw.Bytes.Reader.t 33 + (** [pread_reader ~offset file] creates a reader from [file] starting at 34 + [offset] bytes. Reads via pread on demand — does not load the file into 35 + memory. 36 + 37 + @param slice_length Maximum bytes per slice (default: 65536). 38 + @param length Number of bytes to read (default: to end of file). *) 39 + 25 40 (** {1 Writers} *) 26 41 27 42 val bytes_writer_of_flow :