diff options
| author | Robert | 2017-10-19 18:22:44 +0200 |
|---|---|---|
| committer | Robert | 2017-10-24 15:28:44 +0200 |
| commit | 7f3b2aa1a1c4a2e051e1b2d3d3b57ab646b01a44 (patch) | |
| tree | 2422d8465d8487fef610ffeb88a9d96a56af1c4f /app | |
| parent | 302ed0f642c755b6f96def25eda25e2d2dae8891 (diff) | |
| download | chouette-core-7f3b2aa1a1c4a2e051e1b2d3d3b57ab646b01a44.tar.bz2 | |
Refs: #4633@0.5h;
Speced and implemented ZipService to return additional directories
in the entry's `spurious` field.
Diffstat (limited to 'app')
| -rw-r--r-- | app/services/zip_service.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb index cab301b01..7a4bdad1b 100644 --- a/app/services/zip_service.rb +++ b/app/services/zip_service.rb @@ -1,10 +1,9 @@ class ZipService - # TODO: Remove me before merge https://github.com/rubyzip/rubyzip - class Subdir < Struct.new(:name, :stream) + class Subdir < Struct.new(:name, :stream, :spurious) end - attr_reader :current_key, :current_output, :yielder + attr_reader :current_key, :current_output, :current_spurious, :yielder def initialize data @zip_data = StringIO.new(data) @@ -36,6 +35,7 @@ class ZipService end def add_to_current_output entry + return if is_spurious! entry.name current_output.put_next_entry entry.name write_to_current_output entry.get_input_stream end @@ -51,7 +51,8 @@ class ZipService @yielder << Subdir.new( current_key, # Second part of the solution, yield the closed stream - current_output.close_buffer) + current_output.close_buffer, + current_spurious) end end @@ -59,10 +60,19 @@ class ZipService @current_key = entry_key # First piece of the solution, use internal way to create a Zip::OutputStream @current_output = Zip::OutputStream.new(StringIO.new(''), true, nil) + @current_spurious = [] end def entry_key entry # last dir name File.dirname.split("/").last entry.name.split('/', -1)[-2] end + + def is_spurious! entry_name + segments = entry_name.split('/', 3) + return false if segments.size < 3 + + current_spurious << segments.second + return true + end end |
