Skip to content

Instantly share code, notes, and snippets.

@hirakiuc
Last active August 16, 2017 08:58
Show Gist options
  • Select an option

  • Save hirakiuc/bcb7991ff3b01405f4f2 to your computer and use it in GitHub Desktop.

Select an option

Save hirakiuc/bcb7991ff3b01405f4f2 to your computer and use it in GitHub Desktop.
StringIO with binary in ruby
require 'stringio'
# Create StringIO object from binary data file
StringIO.new(File.binread('pict.jpg'), 'rb')
# Create StringIO object from text data file
StringIO.new(File.read('memo.txt', encoding: Encoding::UTF_8), 'r')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment