crystal-lang


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
You can just use IO#write(Slice):
STDOUT.write(slice)

Related Links

Crystal C bindings: argument const unsigned char **
Crystal C bindings: return type char*
Make Class member attribute of type Array(T) accept 2D arrays of T
JSON.mapping if “root” attribute has inherit keys
Crystal C bindings: using fopen
Define Class object validations
Set attribute of type “Class” to define it as Int32, String, Float64
Set both default attribute and type of attribute
How can I test private methods?
Write binary data to stdout in Crystal
Unable to compile after upgrade from crystal 0.19.4 to 0.20
Application server for Crystal web app / Kemal
Crystal Fiber error - “Unhandled exception in spawn: SSL_shutdown: Operation now in progress (Errno)”
Convert hex string to int in Crystal
Crystal convert string to hash from response.body
Crystal no overload matches 'Array(Type)#[]' with type (Int32 | Nil)

Categories

HOME
asp.net-web-api
turing-machines
fuelux
string
rsa
toolbox
themes
appcelerator
vxml
onclick
babeljs
android-json
plist
3nf
package-managers
azure-powershell
nodemcu
connector
sar
ksh
named-entity-recognition
roslyn
definitelytyped
stackexchange
flooding
fractions
angular-translate
iis-express
uitapgesturerecognizer
alm
magento-1.8
eviews
recurring-events
database-comparison
cart
quickfixj
erb
android-gridview
classcastexception
navigator
engine.io
reason
wurfl
tasm
visa
importerror
lampp
builder
gitlist
serde
hammer.js
tf
payara-micro
video-conferencing
appdomain
libjpeg
rocks
lrs
jquery-jscrollpane
mediametadataretriever
fink
beanstalk
halcon
computer-architecture
vigenere
google-refine
snackbar
bcache
android-vibration
lambda-architecture
cuba
wxformbuilder
twitter-bootstrap-rails
gtm-oauth2
ebay-lms
nevron
merb
joomla-template
alice
booksleeve
monotouch.dialog
saleslogix
appjs
multiplexing
cgimage
htdocs
jqote
tournament
umra
strsep
squishit
timertask
undefined-index
cruisecontrol.rb
rowlex
hbm2java
dsl-tools
business-model
cardspace
netbeans6.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App