mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[storage|aws] Fix docs to say files.each, not each_file.
each_file was an API that was discussed, but dismissed as a bad idea. The documentation still had a reference to each_file, though.
This commit is contained in:
parent
746f39a526
commit
5aed5ee93e
1 changed files with 23 additions and 6 deletions
|
@ -86,17 +86,34 @@ and maybe some pictures of your cat doing funny stuff. Since this is
|
|||
all of vital importance, you need to back it up.
|
||||
|
||||
# copy each file to local disk
|
||||
directory.each_file do |s3_file|
|
||||
directory.files.each do |s3_file|
|
||||
File.open(s3_file.key, 'w') do |local_file|
|
||||
local_file.write(s3_file.body)
|
||||
end
|
||||
end
|
||||
|
||||
One caveat: it's tempting to just write `directory.files.each` here,
|
||||
but that only works until you get a large number of files. S3's API
|
||||
for listing files forces pagination on you. `directory.each_file`
|
||||
takes pagination into account; `directory.files.each` will only
|
||||
operate on the first page.
|
||||
One caveat: it's way more efficient to do this:
|
||||
|
||||
# do two things per file
|
||||
directory.files.each do |file|
|
||||
do_one_thing(file)
|
||||
do_another_thing(file)
|
||||
end
|
||||
|
||||
than it is to do this:
|
||||
|
||||
# do two things per file
|
||||
directory.files.each do |file|
|
||||
do_one_thing(file)
|
||||
end.each do |file|
|
||||
do_another_thing(file)
|
||||
end
|
||||
|
||||
The reason is that the list of files might be large. Really
|
||||
large. Eat-all-your-RAM-and-ask-for-more large. Therefore, every time
|
||||
you say `files.each`, fog makes a fresh set of API calls to Amazon to
|
||||
list the available files (Amazon's API returns a page at a time, so
|
||||
fog works a page at a time in order to keep its memory requirements sane).
|
||||
|
||||
## Sending it out
|
||||
|
||||
|
|
Loading…
Reference in a new issue