type error = | Invalid_byte of int | Appears when the header of the PACK file is wrong. |
| Reserved_kind of int | Appears when the kind of the current PACK object is |
| Invalid_kind of int | Appears when the kind of the current PACK object is undefined. TODO: this case does not appear, lol ... |
| Inflate_error of Inflate.error | Appears when the |
| Hunk_error of HDec.error | Appears when the |
| Hunk_input of int * int | The Hunk object is length-defined. So, when we try to decode this specific PACK object, if the decoder |
| Invalid_length of int * int | Appears when the length of the inflated object does not correspond by what was it noticed by the PACK file. |
The type error.
type kind = | Commit | |
| Tree | |
| Blob | |
| Tag | |
| Hunk of HDec.hunks | The kind of the PACK object. It can be:
|
val default : Cstruct.t -> Inflate.window -> tdefault tmp window makes a new decoder of a PACK file.
tmp is a Cstruct.t used as an internal output of the inflated stream. We let the user to allocate the optimized length for this temporary buffer and we take the ownership (so, you don't use it to another compute).
window is the Inflate.window needed to inflate. We keep this window as long as we use have objects in the PACK stream and reset it for each object (and avoid any needed allocation). Then, we take the ownership so you are not able to use it for another process.
This state does not allocate any large caml value.
val many : t -> int32many t returns how many objects will/did compute for the current stream.
val from_window : Unpack.Window.t -> int -> Cstruct.t -> Inflate.window -> tfrom_window pack_window off_in_window tmp window makes a new decoder of a PACK file specialized from a Window.t. This decoder compute only one object in a precise offset (noticed by pack_window and the relative offset off_in_window). Then tmp and window have the same purpose than default. For this state, eval has a different behaviour. Indeed, after the specified object de-serialized, eval returns directly `End even if it's not the last object in the PACK stream. Then, the hash produced is empty.
val process_length : Unpack.Window.t -> int -> Cstruct.t -> Inflate.window -> tprocess_length pack_window off_in_window tmp window makes a new specific decoder only to get the real length of the PACK object specified by pack_window and the relative offset off_in_window. This decoder is only able to be used with eval_length (and not eval). For all git object, we can catch the real inflated length of the expected object. For the Hunk _ object, we can get the real inflated length of the PACK object and call H.partial_hunks with the internal Hunk decoder state. This compute appear only when eval_length returns `Length.
This decoder is focused to only get the length of the PACK object. So we inflate for example only what it needed to get this information. So, obviously, it is more faster than eval and compute all of the object to get the information then.
val process_metadata : Unpack.Window.t -> int -> Cstruct.t -> Inflate.window -> tprocess_metadata same purpose than process_length but stop the decoder to a step to get some meta-data about the expected PACK object.
refill off len t provides a new t with len bytes to read, starting at off. This byte range is read by calls to eval with t until `Await is returned.
next_object t provides a new t which continue the de-serialization of the PACK stream. Indeed, when the client catches a new `Object, the decoder sticks on the this situation. So to move to the next step, the client have to call next_object to continue the process.
continue t defers H.continue to the internal state H.t. The client is able to use it only when eval/eval_length/eval_metadata returns `Hunk.
kind t returns the kind of the current object. The client is able to use this function only when eval returns `Object or `Hunk. Otherwise, we raise an Invalid_argument. This function is available when the client process the meta-data of the expected object and can call it when eval_metadata returns `Metadata.
val length : t -> intlength t returns the real inflated length of the current object in the PACK stream. The client is able to use this function only when eval returns `Object or `Hunk. Otherwise, we raise an Invalid_argument. This function is available when the client process the length of the expected object and can call it when eval_length returns `Length.
val offset : t -> int64offset t returns the absolute offset of the current object in the PACK file. The client is able to use this function only when eval returns `Object or `Hunk. Otherwise, we raise an Invalid_argument. This function is available when the client process the meta-data of the expected object and can call it when eval_metadata returns `Metadata.
val consumed : t -> intconsumed t returns how many byte(s) the decoder consumed to de-serialize the current/expected object in the PACK stream. The client is able to use it only when eval returns `Object. Otherwise, we raise an Invalid_argument.
val crc : t -> Checkseum.Crc32.tcrc t returns the CRC-32 checksum computed when the decoder consumed all byte(s) needed to de-serialize the current/expected object. The client is able to use this function only when eval returns `Object. Otherwise, we raise an Invalid_argument.
output t returns the output produced by the decoder t when it inflates a git object. The Cstruct.t is physically the same than tmp noticed when the client makes the decoder t. Then, output returns how many byte(s) the decoder wrote inside tmp. The client is able to use this function only when the kind of the current pack object processed is different to Hunk. Otherwise, we raise an error.
val eval : Cstruct.t -> t -> [ `Object of t | `Hunk of t * HDec.hunk | `Await of t | `Flush of t | `End of t * Hash.t | `Error of t * error ]eval src t is:
`Await tifftmore input storage. The client muse userefillto provide a new buffer and then callevalwith`Awaituntil other value returned.`Object tifftfinishes to compute one object. The client is able to use the meta-data functions (likekindorcrc) and should usenext_objectto move the decoder to the next step. Otherwise, the decodertsticks in this situation.Hunk (t, hunk)defers the value returned by the internalH.tdecoder. The client should usecontinueto move the decoder to the next step. In this situation, we ensure than the futurekindof the current/expected object isHunk _.`Flush tifftneeds more output storage. The client must useflushto provide a new buffer and then callevalwith`Flushuntil`Objectis returned. In this situation, we ensure than the futurekindof the current/expected object is different than theHunk _.`End (t, hash)when the decoder is done.tsticks to this situation. The client can remove it. We return the hash produced by the PACK stream.`Error (t, exn)iff the decoder meet anerrorexn. The decoder can't continue and sticks in this situation.