40 lines
964 B
OCaml
40 lines
964 B
OCaml
|
type t
|
||
|
= DelicatedFile of {
|
||
|
fid : Bytes.t;
|
||
|
aid : Bytes.t option;
|
||
|
files : t list;
|
||
|
}
|
||
|
| ElementaryFile of {
|
||
|
fid : Bytes.t;
|
||
|
sid : Bytes.t;
|
||
|
data : Bytes.t;
|
||
|
}
|
||
|
|
||
|
let find_by_fid fid files =
|
||
|
let rec eachfile = fun file ->
|
||
|
match file with
|
||
|
| DelicatedFile df -> if Bytes.equal fid df.fid
|
||
|
then true
|
||
|
else List.exists eachfile df.files
|
||
|
| ElementaryFile ef -> Bytes.equal fid ef.fid
|
||
|
in
|
||
|
List.find_opt eachfile files
|
||
|
|
||
|
let find_by_aid aid files =
|
||
|
let rec eachfile = fun file ->
|
||
|
match file with
|
||
|
| ElementaryFile _ -> false
|
||
|
| DelicatedFile df -> match df.aid with
|
||
|
| Some id -> Bytes.equal aid id
|
||
|
| None -> List.exists eachfile df.files
|
||
|
in
|
||
|
List.find_opt eachfile files
|
||
|
|
||
|
let find_by_sid sid files =
|
||
|
let rec eachfile = fun file ->
|
||
|
match file with
|
||
|
| DelicatedFile df -> List.exists eachfile df.files
|
||
|
| ElementaryFile ef -> Bytes.equal sid ef.sid
|
||
|
in
|
||
|
List.find_opt eachfile files
|