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

Sharing variables between different macros
passing json to a superclass using .from_json
execution of command failed with code: 1: `cc -o "/root/.cache/crystal/var-app-staging-new-http.cr
How to use union in “if” statement [Crystal]
How to convert a hex string to bytes array in Crystal?
is INSTANCE = new in class is run after compilation automatically or the first time it is accessed?
Crystal lang: understanding method return type of Void
Crystal-lang httpget basic_auth
How to control using CPU cores [Crystal]
How can I read a slice with other size in crystal?
Unix-style password readline
Cannot find -lxml2 when trying to run crystal spec
How do I access an object's eigenclass in Crystal?
Why does my code never reaches the end when waiting for pipe?
Crystal reading x bytes from file
Getting the first element of an empty Array

Categories

HOME
localization
dns
mjml
pyqt
powerpoint
sitecore
knitr
gradient
r-googlesheets
scripting
square
ado.net
performancepoint
syntaxnet
google-chrome-app
text-mining
jsonpath
symmetricds
heat
azure-powershell
null-pointer
aws-sdk
template-engine
symfony-console
breadth-first-search
kendo-mobile
springfox
href
dataflow-diagram
event-store
tosca
google-api-client
windows-server-2003
interbase
vex
ntp
alm
autodesk-designautomation
aws-codecommit
dumpbin
dynamic-jasper
xcode7.3
connection-pool
skylink
preloader
microsoft-metro
optimizely
term
yii2-api
identification
openblas
zenhub
qtranslate
static-cast
java-6
lsyncd
cd-burning
swingworker
rxtx
visual-studio-2008-sp1
resourcemanager
neon
wso2developerstudio
appscale
data-protection
boost-serialization
phpgrid
dynamics-nav-2016
django-urls
zen-cart
binomial-theorem
keyup
botan
fail2ban
mruby
ghcjs
webfinger
lambda-architecture
kissfft
jquery-slider
radiant
android-framework
synapse
high-resolution
code-duplication
inputmismatchexception
isqlquery
mvc-editor-templates
abstract-data-type
dolby-audio-api
android-icons
video-codecs
joomla3.1
frameworkelementfactory
floating-point-exceptions
update-statement
exponentiation
lr
rmdir
uipagecontrol
inline-formset
socketserver
luajava
vs-android
jqueryform
fault-tolerance
image-capture

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App