Only doing fwrite and rewind in stream factory when data is present