-
-
Save sgrove/ebecfee7fa3bed126fe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Generated by: ocaml-crunch | |
Creation date: Sat, 6 Feb 2016 18:32:57 GMT *) | |
module Internal = struct | |
let d_7a56970cd5914782ab48c13383592830 = "tls\n" | |
let file_chunks = function | |
| ".gitignore" | "/.gitignore" -> Some [ d_7a56970cd5914782ab48c13383592830; ] | |
| _ -> None | |
let file_list = [".gitignore"; ] | |
let size = function | |
|".gitignore" |"/.gitignore" -> Some 4L | |
|_ -> None | |
end | |
open Lwt | |
type t = unit | |
type error = | |
| Unknown_key of string | |
type id = unit | |
type 'a io = 'a Lwt.t | |
type page_aligned_buffer = Cstruct.t | |
let id () = () | |
let size () name = | |
match Internal.size name with | |
| None -> return (`Error (Unknown_key name)) | |
| Some s -> return (`Ok s) | |
let filter_blocks offset len blocks = | |
List.rev (fst (List.fold_left (fun (acc, (offset, offset', len)) c -> | |
let len' = String.length c in | |
let acc, consumed = | |
if len = 0 | |
then acc, 0 | |
(* This is before the requested data *) | |
else if offset' + len' < offset | |
then acc, 0 | |
(* This is after the requested data *) | |
else if offset + len < offset' | |
then acc, 0 | |
(* Overlapping: we're inside the region but extend beyond it *) | |
else if offset <= offset' && (offset' + len') >= (offset + len) | |
then String.sub c (offset' - offset) len :: acc, len | |
(* Overlapping: we're outside the region but extend into it *) | |
else if offset' <= offset | |
then String.sub c (offset - offset') (len' - offset + offset') :: acc, (len' - offset + offset') | |
(* We're completely inside the region *) | |
else c :: acc, len' in | |
let offset' = offset' + len' in | |
let offset = offset + consumed in | |
let len = len - consumed in | |
acc, (offset, offset', len) | |
) ([], (offset, 0, len)) blocks)) | |
let read () name offset len = | |
match Internal.file_chunks name with | |
| None -> return (`Error (Unknown_key name)) | |
| Some c -> | |
let bufs = List.map (fun buf -> | |
let pg = Io_page.to_cstruct (Io_page.get 1) in | |
let len = String.length buf in | |
Cstruct.blit_from_string buf 0 pg 0 len; | |
Cstruct.sub pg 0 len | |
) (filter_blocks offset len c) in | |
return (`Ok bufs) | |
let return_ok = return (`Ok ()) | |
let connect () = return_ok | |
let disconnect () = return_unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment