comparison app/controllers/pastes_controller.rb @ 226:fb9909885d63

Also support plain gzip
author Edho Arief <edho@myconan.net>
date Mon, 13 May 2013 13:19:33 +0900
parents 9998d8b6c524
children 388504e43bcf
comparison
equal deleted inserted replaced
225:9998d8b6c524 226:fb9909885d63
29 29
30 # POST / 30 # POST /
31 # POST /pastes.json 31 # POST /pastes.json
32 # POST /pastes.txt 32 # POST /pastes.txt
33 def create 33 def create
34 if params[:paste] && params[:paste][:paste_gzip_base64] 34 if params[:paste].is_a? Hash
35 # 1. decode from base64 35 if params[:paste][:paste_gzip_base64]
36 # 2. create StringIO from decoded string 36 # 1. decode from base64
37 # 3. unzip and read the stream 37 # 2. create StringIO from decoded string
38 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste].delete(:paste_gzip_base64)))).read 38 # 3. unzip and read the stream
39 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(Base64.decode64(params[:paste].delete(:paste_gzip_base64)))).read
40 elsif params[:paste][:paste_gzip]
41 params[:paste][:paste] = Zlib::GzipReader.new(StringIO.new(params[:paste].delete(:paste_gzip))).read
42 end
39 end 43 end
40 @paste = Paste.new(paste_params.merge(ip: request.remote_ip)) 44 @paste = Paste.new(paste_params.merge(ip: request.remote_ip))
41 45
42 begin 46 begin
43 respond_to do |format| 47 respond_to do |format|