Sha256: 4846666650bbfa324540006a871c9d801b5f968dabb044a8a31dd04f674ce5eb

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

require_relative "ob64/version"
require_relative "ob64_ext"

module Ob64
  include LibBase64
  extend LibBase64

  module_function

  def encode(bin)
    __encode(bin)
  end

  def decode(string)
    __decode(string)
  end

  def urlsafe_encode(bin, padding: true)
    string = __encode(bin)
    string.chomp!("==") || string.chomp!("=") unless padding
    string.tr!("+/", "-_")
    string
  end

  def urlsafe_decode(string)
    if !string.end_with?("=") && string.length % 4 != 0
      string = string.ljust((string.length + 3) & ~3, "=")
      string.tr!("-_", "+/")
    else
      string = string.tr("-_", "+/")
    end
    __decode(string)
  end

  def encoded_length_of(bin, padding: true)
    __encoded_length_of(bin, padding)
  end

  def decoded_length_of(string)
    __decoded_length_of(string)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ob64-0.1.0 lib/ob64.rb