Fumisky Wells
Fumisky Wells

Reputation: 1199

When uploading a file in Fog storage, closing a ruby file object is not required?

Whan I looked at Fog document at http://fog.io/storage/, the example says:

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

File.open(...) returns the file object, but I wonder when it is closed? Is the following more resourse conservative or it doesn't matter?:

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

Upvotes: 0

Views: 140

Answers (1)

geemus
geemus

Reputation: 2542

I don't think in that case it would be explicitly closed (so perhaps the docs should be updated). The leftover would just be the file handle, which shouldn't be too impactful (vs the contents of the file, which should only be used a little at a time and release). So the second, conservative option you list is probably more correct, but in most cases it probably won't matter too much either way.

Upvotes: 2

Related Questions