Ruby Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Ruby
Examples

Quick Start
Ruby Unicode
Ruby Byte Array
Ruby Certs
Ruby Email
Ruby Encryption
Ruby FTP
HTML-to-XML
Ruby HTTP
Ruby IMAP
Ruby MHT
Ruby MIME
Ruby S/MIME
Ruby Signatures
Ruby RSA
Ruby Socket
Ruby Spider
Ruby Tar
Ruby Upload
Ruby XML
Ruby XMP
Ruby Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
LZW
Bz2
Icon

 

 

 

 

 

 

 

beginsWith -- Check if Byte Array Begins with Byte Sequence

Determine if a byte array begins with a specific byte sequence.

Download Chilkat Ruby Library

require 'chilkat'

zipData = Chilkat::CkByteData.new()
gifData = Chilkat::CkByteData.new()

#  Zip files begin with these 4 bytes:
zipBegin_bytes = [ 0x50, 0x4B, 3, 4 ]
zipBegin = Chilkat::CkByteData.new()
zipBegin.append(zipBegin_bytes.pack("C4"), 4)

#  GIF files begin with "GIF89", which is this byte sequence:
gifBegin_bytes = [ 0x47, 0x49, 0x46, 0x38, 0x39 ]
gifBegin = Chilkat::CkByteData.new()
gifBegin.append(gifBegin_bytes.pack("C5"), 5)

success = zipData.loadFile("dude.zip")
if (success == true)
    if (zipData.beginsWith(zipBegin))
        print "Yes, this is a .zip archive!" + "\n";
    else
        print "No, this is not a .zip archive." + "\n";
    end

else
    print "Failed to load dude.zip" + "\n";
end

success = gifData.loadFile("dude.gif")
if (success == true)
    if (gifData.beginsWith(gifBegin))
        print "Yes, this is a GIF image!" + "\n";
    else
        print "No, this is not a GIF image." + "\n";
    end

else
    print "Failed to load dude.gif" + "\n";
end

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.