Creating a thread-safe temporary file name

后端 未结 4 729
既然无缘
既然无缘 2020-12-29 21:18

When using Tempfile Ruby is creating a file with a thread-safe and inter-process-safe name. I only need a file name in that way.

I was wondering if ther

4条回答
  •  时光取名叫无心
    2020-12-29 21:39

    Since you only need the filename, what about using the SecureRandom for that:

    require 'securerandom'
    
    filename =  "#{SecureRandom.hex(6)}.png" #=> "0f04dd94addf.png"
    

    You can also use SecureRandom.alphanumeric

提交回复
热议问题