Trim leading/trailing bytes from a stream