Sha256: 1d455d59040793d6082e8c55bd5bc244daea728e7aa007b8b0edf0a0e41fe7c9

Contents?: true

Size: 845 Bytes

Versions: 3

Compression:

Stored size: 845 Bytes

Contents

module Python
  module Pickle
    #
    # Represents a Python `bytearray` object.
    #
    class ByteArray < String

      # Mapping of python `codecs` encoding names and their Ruby equivalents.
      #
      # @api private
      ENCODINGS = {
        nil       => Encoding::ASCII_8BIT,
        'latin-1' => Encoding::ISO_8859_1
      }

      #
      # Initializes the byte array.
      #
      # @param [String] string
      #   The contents of the byte array.
      #
      # @param [String, nil] encoding
      #   The optional encoding name.
      #
      def initialize(string='', encoding=nil)
        super(string, encoding: ENCODINGS.fetch(encoding))
      end

      #
      # Inspects the byte array object.
      #
      # @return [String]
      #
      def inspect
        "#<#{self.class}: #{super}>"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
python-pickle-0.2.0 lib/python/pickle/byte_array.rb
python-pickle-0.1.1 lib/python/pickle/byte_array.rb
python-pickle-0.1.0 lib/python/pickle/byte_array.rb