From: "matz (Yukihiro Matsumoto) via ruby-core" <ruby-core@...> Date: 2024-05-21T15:59:15+00:00 Subject: [ruby-core:117958] [Ruby master Feature#20497] Tempfile.create_io Issue #20497 has been updated by matz (Yukihiro Matsumoto). From what I understand, the real intent of this proposal is to "let the OS clean up after the generated tempfile". If so, I don't think the name `create_io` represents the intent. I vote for adding a keyword argument to `Tempfile.create`. Matz. ---------------------------------------- Feature #20497: Tempfile.create_io https://bugs.ruby-lang.org/issues/20497#change-108375 * Author: akr (Akira Tanaka) * Status: Open ---------------------------------------- I propose Tempfile.create_io. It is similar to Tempfile.create but the actual file is unlinked before returning the method. https://github.com/ruby/ruby/pull/10803 Purpose: Sometimes, applications need a temporary file but it is not required to access via a pathname. In this case, the created file can be unlinked just after temporary file creation. This removes the obligation of removing the file from applications. So, Tempfile.create_io is easier to use than Tempfile.create. Example: ``` tmpio = Tempfile.create_io # => #<IO:fd 5> tmpio.class # => IO tmpio.path # => nil tmpio.stat.mode.to_s(8) # => "100600" tmpio.puts "foo" tmpio.rewind tmpio.read # => "foo\n" tmpio.close ``` Portability: This feature (unlink just after file creation) is supported on Unix for a long time. Linux 3.11 has O_TMPFILE to create an unnamed file. The current implementation uses it. I heard that it is possible on Windows. (O_SHARE_DELETE?) I'm not sure how to use it. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/