fix readChunk to better handle empty input