Sha256: 1d0ea0edfd98cdf20fca6e9c584fc15e6d442beeee938ba361f7b944ac8b4024

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

Contents

require 'zlib'
require 'httparty'

module AnswersEngine
  module Client
    class BackblazeContent
      include HTTParty    
      
      def get_content(url)
        self.class.get(url, format: :plain)
      end

      def get_gunzipped_content(url)
        # Zlib.gunzip(get_content(url))
        gunzip(get_content(url))
      end

      def gunzip(string)
        sio = StringIO.new(string)
        gz = Zlib::GzipReader.new(sio, encoding: Encoding::ASCII_8BIT)
        _content = ""
        begin 
          _content = gz.read
        rescue => e
          # if unexpected eof error, then readchar until error, and ignore it
          if e.to_s == 'unexpected end of file'
            begin 
              while !gz.eof?
                _content += gz.readchar
              end
            rescue => e
              puts "Ignored Zlib error: #{e.to_s}"
            end
          else 
            raise e
          end
        end

        return _content
      ensure
        gz.close if gz.respond_to?(:close)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
answersengine-0.10.1 lib/answersengine/client/backblaze_content.rb
answersengine-0.10.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.9.1 lib/answersengine/client/backblaze_content.rb
answersengine-0.9.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.8.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.7.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.6.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.5.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.4.1 lib/answersengine/client/backblaze_content.rb
answersengine-0.4.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.3.3 lib/answersengine/client/backblaze_content.rb
answersengine-0.3.2 lib/answersengine/client/backblaze_content.rb
answersengine-0.3.1 lib/answersengine/client/backblaze_content.rb
answersengine-0.3.0 lib/answersengine/client/backblaze_content.rb
answersengine-0.2.33 lib/answersengine/client/backblaze_content.rb