Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

June 12, 2007

Read Binary File in Ruby

This example shows how the CkByteData object can be used to read and write binary files in Ruby. The CkByteData object is a container for binary data. It provides methods allowing the data to be manipulated and accessed, saved and loaded. The CkByteData.getData method can be called to copy the binary data into a Ruby binary string.

require 'chilkat'
byteData =
# Load a binary file into the CkByteData object.
# Save the binary data to a file.
# Write the file using Ruby.
f ="",  "wb")
# In Ruby, a String object holds and manipulates an
# arbitrary sequence of bytes, typically representing characters --
# but the bytes can just as well be binary data.
# Get the bytes as a binary string (of bytes)
s = byteData.getData()
# how many bytes are there?
print s.size.to_s() + "\n"
# save the bytes to a file:
f ="",  "wb")

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.