Clean up file opening for serialization (#29221)
Summary:
Stacked PRs
* https://github.com/pytorch/pytorch/issues/29232 - Add zipfile serialization
* https://github.com/pytorch/pytorch/issues/29228 - Expose miniz to Python
* **https://github.com/pytorch/pytorch/issues/29221 - Clean up file opening for serialization**
This is a small refactor to get things started for zipfile-based serialization
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29221
Differential Revision: D18330932
Pulled By: driazati
fbshipit-source-id: ce91542faf987ae5aa6dfd322e633a0c7335e678