Find the fifth byte : StringIO « File Directory « Ruby






Find the fifth byte


require 'stringio'
def fifth_byte(file)
  file.seek(5)
  file.read(1)
end

fifth_byte(StringIO.new("123456"))          # => "6"

 








Related examples in the same category

1.Performing Random Access on Read-Once Input Streams
2.Pretending a String is a File
3.Write to a string
4.YAML.dump
5.push data to string
6.Redirecting Standard Input or Output