I am a bit puzzled over how to send a file from an http server to a client(web-browser).
First I send the header and my next task is to send the file content. However I want to send it in segments of say 512 bytes instead of the whole file at once as I ran into some problems.
I am a bit lost on how to achieve that. Here is what I want
read file1;
while (seg=get_next_segment(file1)){
do
send(seg)
until (seg_is_sent)
}
However I can’t seem to find the appropriate functions to achieve that. fread and fseek crossed through my mind but the first one reads the whole file at once and with fseek I don’t see a way to just grab a portion from a file(instead of reading from the file pointer until the end of the file).
freaddoes not read a whole file to the end. It reads exactly how much you tell it to read.Both functions take a size and
nitems. You could set the size to 512, and the number of items to 1 (or vice versa) and read just that portion of the file.