Sha256: 6e8b7f8a65746942f0ff0319fd86863b92f92093b1f510a97d1eeb4f4cabf0bb

Contents?: true

Size: 1.25 KB

Versions: 31

Compression:

Stored size: 1.25 KB

Contents

require 'zlib'
require 'httparty'

module Datahen
  module Client
    class BackblazeContent
      include HTTParty

      def get_content(url)
        self.class.get(url, format: :plain).response.body
      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'
            # heavily improve content read recovery by using "String#<<",
            #  reading all "good" lines and then concat the remaining chars
            begin
              gz.each_line{|line| _content << line}
            rescue => e
              begin
                _content << gz.readchar while !gz.eof
              rescue => e
                puts "Ignored Zlib error: #{e.to_s}"
              end
            end
          else
            raise e
          end
        end

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
datahen-1.6.3 lib/datahen/client/backblaze_content.rb
datahen-1.6.2 lib/datahen/client/backblaze_content.rb
datahen-1.6.1 lib/datahen/client/backblaze_content.rb
datahen-1.6.0 lib/datahen/client/backblaze_content.rb
datahen-1.5.3 lib/datahen/client/backblaze_content.rb
datahen-1.5.2 lib/datahen/client/backblaze_content.rb
datahen-1.5.1 lib/datahen/client/backblaze_content.rb
datahen-1.4.0 lib/datahen/client/backblaze_content.rb
datahen-1.3.2 lib/datahen/client/backblaze_content.rb
datahen-1.3.1 lib/datahen/client/backblaze_content.rb
datahen-1.3.0 lib/datahen/client/backblaze_content.rb
datahen-1.2.3 lib/datahen/client/backblaze_content.rb
datahen-1.2.2 lib/datahen/client/backblaze_content.rb
datahen-1.2.1 lib/datahen/client/backblaze_content.rb
datahen-1.1.2 lib/datahen/client/backblaze_content.rb
datahen-1.1.1 lib/datahen/client/backblaze_content.rb
datahen-1.0.3 lib/datahen/client/backblaze_content.rb
datahen-1.0.2 lib/datahen/client/backblaze_content.rb
datahen-1.0.1 lib/datahen/client/backblaze_content.rb
datahen-1.0.0 lib/datahen/client/backblaze_content.rb