Skip to content

Commit

Permalink
New example for file operations | Read Bytes (#16)
Browse files Browse the repository at this point in the history
* Added read bytes

* Added read bytes
  • Loading branch information
sametaylak authored and askn committed Jul 31, 2018
1 parent 0d0a436 commit aab909a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions file-read-write/file-read-write.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ File.each_line path do |line|
puts line # => Another line
end
# Note that .puts will overwrite previous file contents

# Read bytes
File.open("example.txt") do |io| # This block autoclose file
buffer = Bytes.new(io.size) # Create buffer with io size
io.read(buffer) # Fill buffer with IO
pp buffer
end

0 comments on commit aab909a

Please sign in to comment.