Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › http › BodyWriter › chunkedSendFile Public Function chunkedSendFile Doc Source Public Function std.http.BodyWriter.chunkedSendFile
pub fn chunkedSendFile (w : *Writer , file_reader : *File .Reader , limit : std .Io .Limit ) Writer .FileError !usize Params File http.zig: 961
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995 pub fn chunkedSendFile (w : *Writer , file_reader : *File .Reader , limit : std .Io .Limit ) Writer .FileError !usize {
const bw : *BodyWriter = @alignCast (@fieldParentPtr ("writer" , w ));
assert (!bw .isEliding ());
const data_len = Writer .countSendFileLowerBound (w .end , file_reader , limit ) orelse {
// If the file size is unknown, we cannot lower to a `sendFile` since we would
// have to flush the chunk header before knowing the chunk length.
return error .Unimplemented ;
};
if (data_len == 0 ) return error .EndOfStream ;
const out = bw .http_protocol_output ;
l : switch (bw .state .chunk_len ) {
0 => {
const header_buf = try out .writableArray (chunk_header_template .len );
@memcpy (header_buf , chunk_header_template );
writeHex (header_buf [0 ..chunk_len_digits ], data_len );
bw .state .chunk_len = data_len + 2 ;
continue :l bw .state .chunk_len ;
},
1 => unreachable , // Wrote more data than specified in chunk header.
2 => {
try out .writeAll ("\r\n" );
bw .state .chunk_len = 0 ;
continue :l 0 ;
},
else => {
const chunk_limit : std .Io .Limit = .limited (bw .state .chunk_len - 2 );
const n = if (chunk_limit .subtract (w .buffered ().len )) |sendfile_limit |
try out .sendFileHeader (w .buffered (), file_reader , sendfile_limit .min (limit ))
else
try out .write (chunk_limit .slice (w .buffered ()));
bw .state .chunk_len -= n ;
return w .consume (n );
},
}
}