A problem with chunked IIRC is that the frame headers are variable-length (a CRLF followed by a hex number followed by some optional gunk followed by CRLF) so you have to drop back into one-byte-at-a-time to read it. (Well, I suppose you could read 5 bytes, which is the minimum: CR, LF, X, CR, LF, and when the second CR isn't among these, you have a lower bound for how much more to read, although at that point you better load up on coffee before writing the rest of the code. :-)
Some good things about it:
- Explicit final frame (byte count zero), so no need to rely on the data to know the end.