is there an existing FileInputStream delete on close?

I know this is a fairly old question; however, it’s one of the first results in Google, and Java 7+ has this functionality built in: Path path = Paths.get(filePath); InputStream fileStream = Files.newInputStream(path, StandardOpenOption.DELETE_ON_CLOSE); There are a couple caveats with this approach though, they’re written up here, but the gist is that the implementation makes … Read more

Is there any way to make a Ruby temporary file permanent?

Not really. For the question itself, see this: ObjectSpace.undefine_finalizer(tmpfile) The Tempfile library uses Ruby ObjectSpace finalizers to automatically delete itself on garbage collection. By using the above line you can remove the Tempfile’s ability to delete itself if you don’t delete it. So, for example: $ irb 2.0.0p0 :001 > require “tempfile” => true 2.0.0p0 … Read more

tmpnam warning saying it is dangerous

From tmpnam manpage : The tmpnam() function generates a different string each time it is called, up to TMP_MAX times. If it is called more than TMP_MAX times, the behavior is implementation defined. Although tmpnam() generates names that are difficult to guess, it is nevertheless possible that between the time that tmpnam() returns a pathname, … Read more

Python: How do I make temporary files in my test suite?

FWIW using py.test you can write: def test_function(tmpdir): # tmpdir is a unique-per-test-function invocation temporary directory Each test function using the “tmpdir” function argument will get a clean empty directory, created as a sub directory of “/tmp/pytest-NUM” (linux, win32 has different path) where NUM is increased for each test run. The last three directories are … Read more

Pipe vs. Temporary File

One big difference is that with the pipe, processes A and B can be running concurrently, so that B gets to work on the output from A before A has finished producing it. Further, the size of the pipe is limited, so A won’t be able to produce vastly more data than B has consumed; … Read more

Can I delete data from the iOS DeviceSupport directory?

The ~/Library/Developer/Xcode/iOS DeviceSupport folder is basically only needed to symbolicate crash logs. You could completely purge the entire folder. Of course the next time you connect one of your devices, Xcode would redownload the symbol data from the device. I clean out that folder once a year or so by deleting folders for versions of … Read more

How to save UploadFile in FastAPI

Background UploadFile is just a wrapper around SpooledTemporaryFile, which can be accessed as UploadFile.file. SpooledTemporaryFile() […] function operates exactly as TemporaryFile() does And documentation about TemporaryFile says: Return a file-like object that can be used as a temporary storage area. [..] It will be destroyed as soon as it is closed (including an implicit close … Read more