(PureBasic) Load Entire File into BinData
Demonstrates how to load an entire file into a BinData object.
IncludeFile "CkBinData.pb"
IncludeFile "CkFileAccess.pb"
Procedure ChilkatExample()
fac.i = CkFileAccess::ckCreate()
If fac.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkFileAccess::ckOpenForRead(fac,"qa_data/pdf/sample.pdf")
If success = 0
Debug CkFileAccess::ckLastErrorText(fac)
CkFileAccess::ckDispose(fac)
ProcedureReturn
EndIf
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
maxBytesToRead.i = 99999999
success = CkFileAccess::ckFileReadBd(fac,maxBytesToRead,bd)
If success = 0
Debug CkFileAccess::ckLastErrorText(fac)
CkFileAccess::ckDispose(fac)
CkBinData::ckDispose(bd)
ProcedureReturn
EndIf
CkFileAccess::ckFileClose(fac)
; The bd object contains the file data...
success = CkBinData::ckWriteFile(bd,"qa_output/sample.pdf")
CkFileAccess::ckDispose(fac)
CkBinData::ckDispose(bd)
ProcedureReturn
EndProcedure
|