Sha256: 9bf262fccbc32fc030a62b00cf8c9eebbfcb58256b336df4cdd303c55111a9af

Contents?: true

Size: 1.02 KB

Versions: 25

Compression:

Stored size: 1.02 KB

Contents

require 'zlib'
require 'httparty'

module Datahen
  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

25 entries across 25 versions & 1 rubygems

Version Path
datahen-0.14.22 lib/datahen/client/backblaze_content.rb
datahen-0.14.21 lib/datahen/client/backblaze_content.rb
datahen-0.14.20 lib/datahen/client/backblaze_content.rb
datahen-0.14.19 lib/datahen/client/backblaze_content.rb
datahen-0.14.18 lib/datahen/client/backblaze_content.rb
datahen-0.14.17 lib/datahen/client/backblaze_content.rb
datahen-0.14.16 lib/datahen/client/backblaze_content.rb
datahen-0.14.15 lib/datahen/client/backblaze_content.rb
datahen-0.14.12 lib/datahen/client/backblaze_content.rb
datahen-0.14.11 lib/datahen/client/backblaze_content.rb
datahen-0.14.10 lib/datahen/client/backblaze_content.rb
datahen-0.14.9 lib/datahen/client/backblaze_content.rb
datahen-0.14.5 lib/datahen/client/backblaze_content.rb
datahen-0.14.4 lib/datahen/client/backblaze_content.rb
datahen-0.14.3 lib/datahen/client/backblaze_content.rb
datahen-0.14.2 lib/datahen/client/backblaze_content.rb
datahen-0.14.1 lib/datahen/client/backblaze_content.rb
datahen-0.14.0 lib/datahen/client/backblaze_content.rb
datahen-0.13.7 lib/datahen/client/backblaze_content.rb
datahen-0.13.0 lib/datahen/client/backblaze_content.rb