Sha256: 8744450451c9fb54dd88b50bf4add3878a2d031dbcd942d4b8b6068ab9a79ee8

Contents?: true

Size: 885 Bytes

Versions: 10

Compression:

Stored size: 885 Bytes

Contents

# coding: utf-8
# frozen_string_literal: true

#
class PDF::Reader
  module Filter # :nodoc:
    # implementation of the AsciiHex stream filter
    class AsciiHex
      def initialize(options = {})
        @options = options
      end

      ################################################################################
      # Decode the specified data using the AsciiHex algorithm.
      #
      def filter(data)
        data.chop! if data[-1,1] == ">"
        data = data[1,data.size] if data[0,1] == "<"
        data.gsub!(/[^A-Fa-f0-9]/,"")
        data << "0" if data.size % 2 == 1
        data.scan(/.{2}/).map { |s| s.hex.chr }.join("")
      rescue Exception => e
        # Oops, there was a problem decoding the stream
        raise MalformedPDFError,
            "Error occured while decoding an ASCIIHex stream (#{e.class.to_s}: #{e.to_s})"
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
pdf-reader-2.6.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.5.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.4.2 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.4.1 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.4.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.3.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.2.1 lib/pdf/reader/filter/ascii_hex.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.4.0/gems/pdf-reader-2.2.0/lib/pdf/reader/filter/ascii_hex.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.5.0/gems/pdf-reader-2.2.0/lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.2.0 lib/pdf/reader/filter/ascii_hex.rb