Skip to content

Instantly share code, notes, and snippets.

@nuna
Created October 31, 2011 02:40
Show Gist options
  • Save nuna/1326789 to your computer and use it in GitHub Desktop.
Save nuna/1326789 to your computer and use it in GitHub Desktop.
open png file as ascii-bit(binary)
$ irb-ruby-1.9.2-p290
ruby-1.9.2-p290 :001 > RUBY_VERSION
=> "1.9.2"
ruby-1.9.2-p290 :002 > File.read('test.png').encoding
=> #<Encoding:UTF-8>
ruby-1.9.2-p290 :003 > image = File.open('test.png', 'r:ascii-8bit'){|f| f.read}
<snip>
ruby-1.9.2-p290 :004 > image.encoding
=> #<Encoding:ASCII-8BIT>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment