(bind-func curl_write_callback
(let ((cdat:curl_dat* null)
(cdat_current_ptr (lambda () (pref-ptr (tref cdat 0) (tref cdat 1))))
;; define your own custom callback to change MAX_BUFFER_SIZE
(MAX_BUFFER_SIZE 1000000))
(lambda (ptr:i8* size:size_t nmemb:size_t dat:i8*)
(let ((total_bytes (* size nmemb)))
(set! cdat (cast dat curl_dat*))
(if (> (+ (tref cdat 1) total_bytes)
MAX_BUFFER_SIZE)
(begin (printf "curl_write_callback buffer overflow!\n") 0)
(begin
(memcpy (cdat_current_ptr) ptr total_bytes)
(tset! cdat 1 (+ (tref cdat 1) total_bytes))
total_bytes))))))