Sample code for 30+ languages & platforms
Swift

Load Entire File into BinData

Demonstrates how to load an entire file into a BinData object.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let fac = CkoFileAccess()!

    success = fac.open(forRead: "qa_data/pdf/sample.pdf")
    if success == false {
        print("\(fac.lastErrorText!)")
        return
    }

    let bd = CkoBinData()!
    var maxBytesToRead: Int = 99999999
    success = fac.fileReadBd(maxNumBytes: maxBytesToRead, binData: bd)
    if success == false {
        print("\(fac.lastErrorText!)")
        return
    }

    fac.fileClose()

    // The bd object contains the file data...
    success = bd.writeFile(path: "qa_output/sample.pdf")

}