You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
575 B
26 lines
575 B
module Storage |
|
class ArchiveService < StorageService |
|
MAX_SIZE = 50 * (1024**2) # 50MiB |
|
|
|
def initialize(archive_io) |
|
super() |
|
@archive = Zip::File.open_buffer(archive_io) |
|
end |
|
|
|
def list_files(folder) |
|
@archive.glob(File.join(folder, "*.*")) |
|
.map(&:name) |
|
end |
|
|
|
def folder_present?(folder) |
|
!list_files(folder).empty? |
|
end |
|
|
|
def get_file_io(file_name) |
|
entry = @archive.get_entry(file_name) |
|
raise "File too large to be extracted" if entry.size > MAX_SIZE |
|
|
|
entry.get_input_stream |
|
end |
|
end |
|
end
|
|
|