yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob 17ade4485abe624ec059fd76b7138d896be872ba 760 bytes (raw)
$ git show v0.0.1:lib/yahns/tmpio.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
# -*- encoding: binary -*-
# Copyright (C) 2009-2013, Eric Wong <normalperson@yhbt.net> et. al.
# License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
require 'tmpdir'

# some versions of Ruby had a broken Tempfile which didn't work
# well with unlinked files.  This one is much shorter, easier
# to understand, and slightly faster (no delegation).
class Yahns::TmpIO < File # :nodoc:

  # creates and returns a new File object.  The File is unlinked
  # immediately, switched to binary mode, and userspace output
  # buffering is disabled
  def self.new
    fp = begin
      super("#{Dir.tmpdir}/#{rand}", RDWR|CREAT|EXCL, 0600)
    rescue Errno::EEXIST
      retry
    end
    unlink(fp.path)
    fp.binmode
    fp.sync = true
    fp
  end
end

git clone git://yhbt.net/yahns.git
git clone https://yhbt.net/yahns.git