Temporary Files
Sometimes, when writing to a file, we don’t care about the data sticking around. We just want it to be there for the duration of our script’s execution, after which it can safely be discarded.
The reasons for doing this are many. We might be using a library that needs to read from a file, but have data in memory. In this case, we can write the data to a temporary file and then pass that file into our library’s code. We might be dealing with data that’s too big to fit in memory but that won’t ultimately be written to the filesystem—buffering an upload before passing it to another service, for example.
On the face of it, the problem seems like a very simple one, and it’s tempting to create our own solution for it. All we need to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access