package bytesrw
Composable byte stream readers and writers for OCaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
bytesrw-0.2.0.tbz
sha512=e3f07dbd808e152cd4b2ea5c2fa3863d4b72f7f97cfa3cd7493a3725c84f39d882042388ee47c9d6acfd30a650c21db429c8264db3d7466cad6e580308b5a2d2
doc/src/bytesrw.unix/bytesrw_unix.ml.html
Source file bytesrw_unix.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
(*--------------------------------------------------------------------------- Copyright (c) 2024 The bytesrw programmers. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) open Bytesrw (* Readers and writers. *) let rec current_pos fd = match Unix.lseek fd 0 Unix.SEEK_CUR with | exception Unix.Unix_error (ESPIPE, _, _) -> 0 | exception Unix.Unix_error (EINTR, _, _) -> current_pos fd | pos -> if pos < 0 then 0 else pos let bytes_reader_of_fd ?pos ?(slice_length = Bytes.Slice.unix_io_buffer_size) fd = let pos = match pos with Some pos -> pos | None -> current_pos fd in let b = Bytes.create (Bytes.Slice.check_length slice_length) in let rec read () = match Unix.read fd b 0 slice_length with | 0 -> Bytes.Slice.eod | count -> Bytes.Slice.make b ~first:0 ~length:count | exception Unix.Unix_error (Unix.EINTR, _, _) -> read () in Bytes.Reader.make ~pos ~slice_length read let bytes_writer_of_fd ?pos ?(slice_length = Bytes.Slice.unix_io_buffer_size) fd = let pos = match pos with Some pos -> pos | None -> current_pos fd in let rec write = function | s when Bytes.Slice.is_eod s -> () | s -> let b = Bytes.Slice.bytes s in let first = Bytes.Slice.first s and length = Bytes.Slice.length s in match Unix.single_write fd b first length with | count when count = length -> () | count -> write (Option.get (Bytes.Slice.drop count s)) | exception Unix.Unix_error (Unix.EINTR, _, _) -> write s in Bytes.Writer.make ~pos ~slice_length write
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>