The methods read_until, read_until_regex and read_bytes all share identical copies of code to read from the socket, assign callback (context safe) and assert that stream is not already reading. This can be moved to a private method in order to reduce repetitive code and ease maintainability.