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 = Chilkat::CkByteData.new()
# Load a binary file into the CkByteData object.
byteData.loadFile("myZip.zip")
# Save the binary data to a file.
byteData.saveFile("out.zip")
# Write the file using Ruby.
f = File.new("newfile.zip", "wb")
f.write(byteData.getData())
f.close
# 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 = File.new("newfile2.zip", "wb")
f.write(s)
f.close