Created
November 21, 2019 15:52
-
-
Save banzera/6c1bae39102cabb529f27ea2bea17672 to your computer and use it in GitHub Desktop.
filtered zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILTER_FILES_REGEX = [ | |
/Thumbs\.db/, # omit OSX thumbs | |
/\~\$/, # omit temp office files | |
/\/\z/, # omit directories | |
] | |
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') | |
Rails.logger.debug "Unpacking file edition: #{file_edition.download_file_name}" | |
Zippy.open(tf.path) do |src_zip| | |
src_zip.paths | |
.delete_if {|path| FILTER_FILES_REGEX.any?{|regex| regex === path} } | |
.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