aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-03-10 13:51:43 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-03-10 13:53:06 +0100
commit9b1990e07e1b3a5c0eedeffbadde705b23e795de (patch)
tree3ac4e694c14be4d77795488067b57de2435426a4
parentec0b75ee44bf5e565db62136380dee883ed22bbb (diff)
downloadvipeval-9b1990e07e1b3a5c0eedeffbadde705b23e795de.tar.gz
vipeval-9b1990e07e1b3a5c0eedeffbadde705b23e795de.zip
Add VIP compression.
It's a special compression for VIP resources.
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock2
-rw-r--r--lib/job_event.rb8
-rw-r--r--lib/vip_pack.rb21
4 files changed, 32 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
index e9952e8..6430653 100644
--- a/Gemfile
+++ b/Gemfile
@@ -30,6 +30,7 @@ gem 'rest-client'
gem 'minitest-rails', group: [:development, :test]
gem 'haml-rails', group: [:development, :test]
+gem 'rubyzip'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
diff --git a/Gemfile.lock b/Gemfile.lock
index 85de409..a2ca928 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -109,6 +109,7 @@ GEM
netrc (~> 0.7)
ruby_parser (3.7.2)
sexp_processor (~> 4.1)
+ rubyzip (1.2.0)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
@@ -159,6 +160,7 @@ DEPENDENCIES
minitest-rails
rails (= 4.1.8)
rest-client
+ rubyzip
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
spring
diff --git a/lib/job_event.rb b/lib/job_event.rb
index fecfec1..af6f6f2 100644
--- a/lib/job_event.rb
+++ b/lib/job_event.rb
@@ -1,4 +1,9 @@
+require 'zip'
+
class JobEvent
+
+ include VipPack
+
def initialize
@ecs=HttpEcs.instance
end
@@ -30,6 +35,7 @@ class JobEvent
# URI#path returns the path with leading "/"
path= URI(job["EvaluationJob"]["resources"]["exercise"]).path[1..-1]
exercise= @ecs.connection[path].delete
+ exercise = unpack(exercise.body) if packed?(exercise.body)
Rails.logger.info "***** JobEvent#fetch_exercise: #{path} = #{exercise}"
exercise
end
@@ -40,6 +46,7 @@ class JobEvent
# URI#path returns the path with leading "/"
path= URI(job["EvaluationJob"]["resources"]["evaluation"]).path[1..-1]
evaluation= @ecs.connection[path].delete
+ evaluation = unpack(evaluation.body) if packed?(evaluation.body)
Rails.logger.info "***** JobEvent#fetch_evaluation: #{path} = #{evaluation}"
evaluation
end
@@ -50,6 +57,7 @@ class JobEvent
# URI#path returns the path with leading "/"
path= URI(job["EvaluationJob"]["resources"]["solution"]).path[1..-1]
solution= @ecs.connection[path].delete
+ solution = unpack(solution.body) if packed?(solution.body)
Rails.logger.info "***** JobEvent#fetch_solution: #{path} = #{solution}"
solution
end
diff --git a/lib/vip_pack.rb b/lib/vip_pack.rb
new file mode 100644
index 0000000..a4162bf
--- /dev/null
+++ b/lib/vip_pack.rb
@@ -0,0 +1,21 @@
+module VipPack
+ def packed?(data)
+ data.start_with?("ZIP:")
+ end
+
+ def unpack(data)
+ if packed?(data)
+ Rails.logger.info "***** JobEvent#unpack: data is zipped."
+ data = data.sub(/^ZIP:/,'')
+ data = Base64.decode64(data)
+ data = Zip::InputStream.open(StringIO.new(data)) do |io|
+ io.get_next_entry
+ io.read
+ end
+ Rails.logger.info "***** JobEvent#unpack: unzipped data = #{data}"
+ else
+ Rails.logger.info "***** JobEvent#unpack: data is not packed."
+ end
+ data
+ end
+end