title: check if string is base64
body: <p>i may recieve these two strings:</p>
  
  <pre><code>    base = Base64.encode64(File.open("/home/usr/Desktop/test", "rb").read)
      =&gt; "YQo=\n"
  
      string = File.open("/home/usr/Desktop/test", "rb").read
      =&gt; "a\n"
  </code></pre>
  
  <p>what i have tried so far is to check string with regular expression i-e. <code>/([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==$)/</code> but this would be very heavy if the file is big.</p>
  
  <p>I also have tried <code>base.encoding.name</code> and <code>string.encoding.name</code> but both returns the same.</p>
  
  <p>I have also seen <a href="https://stackoverflow.com/questions/8571501/how-to-check-whether-the-string-is-base64-encoded-or-not">this post</a> and got regular expression solution but any other solution ?</p>
  
  <p>Any idea ? I just want to get is the string is actually text or base64 encoded text....</p>