【问题标题】:When uploading a file in Fog storage, closing a ruby file object is not required?在 Fog 存储中上传文件时,不需要关闭 ruby​​ 文件对象?
【发布时间】:2017-04-12 07:08:27
【问题描述】:

当我查看 http://fog.io/storage/ 的 Fog 文档时,示例显示:

# 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

【问题讨论】:

    标签: fog


    【解决方案1】:

    我认为在这种情况下它不会被明确关闭(因此也许应该更新文档)。剩下的只是文件句柄,它不应该有太大的影响(与文件的内容相比,文件的内容应该一次只使用一点并释放)。因此,您列出的第二个保守选项可能更正确,但在大多数情况下,这两种方法都可能无关紧要。

    【讨论】:

    • 谢谢!我明白这一点。
    猜你喜欢
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2013-07-10
    相关资源
    最近更新 更多