Fixed closeStreamIdx not flushing unwritten data