Make stream frame checking and saving atomic