mirror of
https://github.com/c-cube/ezcurl.git
synced 2025-12-06 03:05:31 -05:00
30 lines
881 B
OCaml
30 lines
881 B
OCaml
let body = ref ""
|
|
|
|
let url =
|
|
"https://raw.githubusercontent.com/c-cube/ezcurl/refs/heads/main/.ocamlformat"
|
|
|
|
let () =
|
|
match Ezcurl.get ~url () with
|
|
| Error (code, msg) ->
|
|
Format.eprintf "curl error: code `%s` (%s)@." (Curl.strerror code) msg
|
|
| Ok res ->
|
|
body := res.body;
|
|
Format.printf "get: OK@.body=```@.%s@.```@." !body
|
|
|
|
let () =
|
|
let buf = Buffer.create 32 in
|
|
match
|
|
Ezcurl.http_stream ~meth:GET ~url
|
|
~write_into:
|
|
(object
|
|
method on_input bs i len = Buffer.add_subbytes buf bs i len
|
|
method on_close () = ()
|
|
end)
|
|
()
|
|
with
|
|
| Error (code, msg) ->
|
|
Format.eprintf "curl error: code `%s` (%s)@." (Curl.strerror code) msg
|
|
| Ok _res ->
|
|
let new_body = Buffer.contents buf in
|
|
Format.printf "streaming get: OK@.body=```@.%s@.```@." new_body;
|
|
Format.printf "same buf? %b@." (new_body = !body)
|