2017-04-12 26 views
0

煥我看着霧文檔在http://fog.io/storage/,例子說:在霧存儲中上傳文件時,不需要關閉ruby文件對象?

# upload that resume 
file = directory.files.create(
    :key => 'resume.html', 
    :body => File.open("/path/to/my/resume.html"), 
    :public => true 
) 

File.open(...)返回文件對象,但我不知道何時關閉?在下面的詳細地質礦產保守或不要緊?:

# upload that resume 
File.open("/path/to/my/resume.html") do |f| 
    file = directory.files.create(
    :key => 'resume.html', 
    :body => f, 
    :public => true 
) 
end 

回答

1

我不認爲在這種情況下,將可以顯式關閉(這樣或許文檔應更新)。剩下的只是文件句柄,它不應該太有影響(與文件的內容相比,這些內容只能在一次發佈時使用)。因此,您列出的第二個保守選項可能更爲正確,但在大多數情況下,這兩種方式可能無關緊要。

+0

謝謝!我瞭解這一點。 –

相關問題