Skip to content

Instantly share code, notes, and snippets.

@banzera
Created November 21, 2019 03:12
Show Gist options
  • Save banzera/438e96425cd79f66c9bd2e000b84afb2 to your computer and use it in GitHub Desktop.
Save banzera/438e96425cd79f66c9bd2e000b84afb2 to your computer and use it in GitHub Desktop.
filtered_zips
FILTER_FILES_REGEX = [
/Thumbs\.db/, # omit OSX thumbs
/\~\$/, # omit temp office files
/\/\z/, # omit directories
]
def filtered_paths(zip)
zip.paths.delete_if do |path|
FILTER_FILES_REGEX.any?{|regex| regex === path}
end
end
def download_file_edition_and_add_to_zip(file_edition, dst_zip)
open(file_edition.download_url) do |tf|
if file_edition.download_file_name.ends_with?('.zip')
Zippy.open(tf.path) do |src_zip|
filtered_paths(src_zip).each {|path| dst_zip[path] = src_zip[path] }
end
else
dst_zip[file_edition.download_file_name] = tf.read
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment