Skip to content

Commit 973a5dd

Browse files
authored
Merge pull request #19 from talex5/eof
Cope with partial records
2 parents 4de57bb + 998d5a4 commit 973a5dd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fxt/read.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ module Args = struct
5050

5151
let parse t cs : (string * value) * Cstruct.t =
5252
let header = Cstruct.LE.get_uint64 cs 0 in
53-
let cs = Cstruct.shift cs 8 in
5453
let ty = i64 header land 0xf in
5554
let size = i64 (header >>> 4) land 0xfff in
55+
let rest = Cstruct.shift cs (size * 8) in
56+
let cs = Cstruct.shift cs 8 in
5657
let name = i64 (header >>> 16) land 0xffff in
5758
let name, cs = parse_string t name cs in
5859
let value =
@@ -67,8 +68,7 @@ module Args = struct
6768
| 8 -> `Koid (Cstruct.LE.get_uint64 cs 0)
6869
| x -> `Unknown x
6970
in
70-
let cs = Cstruct.shift cs ((size - 1) * 8) in
71-
(name, value), cs
71+
(name, value), rest
7272

7373
let pp_value f = function
7474
| `Int64 x -> Fmt.pf f "%Ld" x
@@ -289,6 +289,7 @@ let records r =
289289
match record t r with
290290
| None -> seq ()
291291
| Some x -> Cons (x, seq)
292+
| exception End_of_file -> Seq.Nil (* File may be being written at the same time *)
292293
)
293294
in
294295
seq

0 commit comments

Comments
 (0)