Class: MindmeisterApi::ZipHelper
- Inherits:
-
Object
- Object
- MindmeisterApi::ZipHelper
- Defined in:
- lib/mindmeister_api/zip_helpers/zip_helper.rb
Overview
ZIP helper
Constant Summary collapse
- MAX_SIZE =
50 * (1024**2)
Instance Method Summary collapse
-
#uncompress_content(content) ⇒ Object
Uncompress a ZIP archive that has come via string (used by HTTP request).
-
#uncompress_file(zip_file) ⇒ Object
Uncompress a ZIP archive file.
Instance Method Details
#uncompress_content(content) ⇒ Object
Uncompress a ZIP archive that has come via string (used by HTTP request)
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mindmeister_api/zip_helpers/zip_helper.rb', line 11 def uncompress_content(content) content_list = MindmeisterApi::ZipContentList.new Zip::InputStream.open(StringIO.new(content)) do |io| while (entry = io.get_next_entry) raise 'File too large when extracted' if entry.size > MAX_SIZE content_list.add(entry.name, io.read) end end content_list end |
#uncompress_file(zip_file) ⇒ Object
Uncompress a ZIP archive file
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mindmeister_api/zip_helpers/zip_helper.rb', line 28 def uncompress_file(zip_file) content_list = MindmeisterApi::ZipContentList.new Zip::File.open(zip_file) do |zip| zip.each do |entry| raise 'File too large when extracted' if entry.size > MAX_SIZE content_list.add(entry.name, entry.get_input_stream.read) end end content_list end |