Mat
Mat

Reputation: 2184

Write binary data to stdout in Crystal

I'm trying to output binary data to stdout (to serve some dynamic binary data using Kemal).

Here is a test:

size = File.size( "./img.png" )
slice = Slice( UInt8 ).new( size )
File.open( "./img.png" ) do |file|
  file.read_fully( slice )
end

I tried without success:

slice
slice.hexdump
slice.hexstring
slice.to_a
slice.to_s
slice.to_unsafe.value

Upvotes: 3

Views: 378

Answers (1)

Jonne Haß
Jonne Haß

Reputation: 4857

You can just use IO#write(Slice):

STDOUT.write(slice)

Upvotes: 2

Related Questions