Azure Blob: Resume a Download with ETag Protection
See more Azure Cloud Storage Examples
Save the account, path, ETag and size in an immutable checkpoint, then append complete byte ranges to a private .part file. A later run uses the existing partial-file length as its offset and checks that HEAD still describes the same blob. Every range carries If-Match and must return the expected ETag, exact Content-Range, Content-Length and body size before any bytes are appended.
The demonstration bounds offsets to 2,000,000,000 bytes so it can use int arithmetic without overflow; this is not an Azure service limit. Sizes in checkpoints remain strings. Only the final successful transfer renames the partial output to the final filename. Empty blobs are handled without issuing an invalid range.
Use one process, an exclusive local destination and an unchanged partial file. The checkpoint does not independently hash or authenticate local content; do not point it at an unrelated file or reuse a partial file that was edited or suffered disk corruption. After a local write failure inspect or restart the partial file. On 412 or changed HEAD properties, preserve the previous partial output and start a new download separately instead of combining versions. A crash while initially publishing the checkpoint fails closed if state is incomplete.
Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.
Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTextCompare
Handle hoConfig
Boolean iSameText1
Boolean iSameText2
Handle hoEndpoint
String sResourcePath
Handle hoRest
Variant vAzAuth
Handle hoAzAuth
Variant vConnection
Handle hoConnection
String sResponseText
Handle hoResult
String sPartFile
String sFinalFile
String sCheckpointFile
Handle hoFiles
String sEtag
Boolean iSameText3
String sTotalText
Handle hoTotalValue
Handle hoTotalDigits
Integer iTotalRemoved
Handle hoTotalNumber
Integer iTotal
Handle hoCheckpoint
Boolean iSameText4
Boolean iSameText5
Boolean iSameText6
String sLocalSize
String sOffsetText
Handle hoOffsetValue
Handle hoOffsetDigits
Integer iOffsetRemoved
Handle hoOffsetNumber
Integer iOffset
Variant vChunk
Handle hoChunk
Handle hoRange
Handle hoExpectedRange
Handle hoExpectedLength
Integer iCount
Integer iEndByte
Integer iHttpStatus
Boolean iSameText7
String sTemp1
String sTemp2
String sTemp3
String sTemp4
Integer iTemp1
Integer iTemp2
Boolean bTemp1
Boolean bTemp2
Move False To iSuccess
// StringBuilder compares text by value in every generated language.
Get Create (RefClass(cComChilkatStringBuilder)) To hoTextCompare
If (Not(IsComObjectCreated(hoTextCompare))) Begin
Send CreateComObject of hoTextCompare
End
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Move False To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoConfig
If (Not(IsComObjectCreated(hoConfig))) Begin
Send CreateComObject of hoConfig
End
Set ComStrict Of hoConfig To True
Get ComLoadFile Of hoConfig "qa_data/azure/storage.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not load private Azure configuration."
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText1
Get ComJsonTypeOf Of hoConfig "account" To iTemp1
If ((iTemp1 <> 1) Or (iSameText1 = True)) Begin
Showln "Supply the storage account name."
Procedure_Return
End
// access_key is the base64 account key, not a connection string or SAS.
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "access_key" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText2
Get ComJsonTypeOf Of hoConfig "access_key" To iTemp1
If ((iTemp1 <> 1) Or (iSameText2 = True)) Begin
Showln "Supply the base64 account access key."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoEndpoint
If (Not(IsComObjectCreated(hoEndpoint))) Begin
Send CreateComObject of hoEndpoint
End
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComAppend Of hoEndpoint sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoEndpoint ".blob.core.windows.net" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
// resourcePath is already URL-encoded. Encode each path segment once when adapting it.
// Keep slash separators; names and paths are case-sensitive.
Move "/examplecontainer/example.bin" To sResourcePath
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Set ComConnectTimeoutMs Of hoRest To 20000
Set ComIdleTimeoutMs Of hoRest To 60000
Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
If (Not(IsComObjectCreated(hoAzAuth))) Begin
Send CreateComObject of hoAzAuth
End
Get ComStringOf Of hoConfig "account" To sTemp1
Set ComAccount Of hoAzAuth To sTemp1
Get ComStringOf Of hoConfig "access_key" To sTemp1
Set ComAccessKey Of hoAzAuth To sTemp1
Set ComService Of hoAzAuth To "Blob"
Set ComScheme Of hoAzAuth To "SharedKey"
Set ComXMsVersion Of hoAzAuth To "2026-04-06"
Get pvComObject of hoAzAuth to vAzAuth
Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
If (iSuccess <> True) Begin
Showln "Could not configure Shared Key signing."
Procedure_Return
End
Get Create (RefClass(cComChilkatSocket)) To hoConnection
If (Not(IsComObjectCreated(hoConnection))) Begin
Send CreateComObject of hoConnection
End
Set ComRequireSslCertVerify Of hoConnection To True
Set ComMaxReadIdleMs Of hoConnection To 60000
Set ComMaxSendIdleMs Of hoConnection To 60000
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS connection failed; inspect diagnostics privately."
Procedure_Return
End
// Do not replay a write automatically after losing its response.
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get Create (RefClass(cComChilkatXml)) To hoResult
If (Not(IsComObjectCreated(hoResult))) Begin
Send CreateComObject of hoResult
End
Set ComStrict Of hoResult To True
Move "qa_output/resume.bin.part" To sPartFile
Move "qa_output/resume.bin" To sFinalFile
Move "qa_data/azure/download-checkpoint.json" To sCheckpointFile
Get Create (RefClass(cComCkFileAccess)) To hoFiles
If (Not(IsComObjectCreated(hoFiles))) Begin
Send CreateComObject of hoFiles
End
Get ComFileExists Of hoFiles sFinalFile To bTemp1
If (bTemp1 = True) Begin
Showln "Choose a new final filename; existing output is preserved."
Procedure_Return
End
Get ComFullRequestNoBody Of hoRest "HEAD" sResourcePath To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Showln "Request did not complete; outcome may be uncertain."
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "HTTP status: " iTemp1
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Showln "Azure error code: " sTemp1
Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
Showln "Request ID: " sTemp1
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
Procedure_Return
End
Get ComResponseHdrByName Of hoRest "ETag" To sEtag
Send ComClear To hoTextCompare
Get ComSetString Of hoTextCompare sEtag To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText3
If (iSameText3 = True) Begin
Showln "Missing blob ETag."
Procedure_Return
End
Get ComResponseHdrByName Of hoRest "Content-Length" To sTotalText
Get Create (RefClass(cComChilkatStringBuilder)) To hoTotalValue
If (Not(IsComObjectCreated(hoTotalValue))) Begin
Send CreateComObject of hoTotalValue
End
Get ComAppend Of hoTotalValue sTotalText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComLength Of hoTotalValue To iTemp1
Get ComLength Of hoTotalValue To iTemp2
If ((iTemp1 < 1) Or (iTemp2 > 10)) Begin
Showln "Invalid or oversized length for this bounded example."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoTotalDigits
If (Not(IsComObjectCreated(hoTotalDigits))) Begin
Send CreateComObject of hoTotalDigits
End
Get ComAppend Of hoTotalDigits sTotalText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Move 0 To iTotalRemoved
Get ComReplace Of hoTotalDigits "0" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "1" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "2" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "3" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "4" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "5" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "6" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "7" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "8" "" To iTotalRemoved
Get ComReplace Of hoTotalDigits "9" "" To iTotalRemoved
Get ComLength Of hoTotalDigits To iTemp1
If (iTemp1 <> 0) Begin
Showln "Length must be a decimal string."
Procedure_Return
End
Get ComLength Of hoTotalValue To iTemp1
Get ComStartsWith Of hoTotalValue "1" True To bTemp1
Get ComContentsEqual Of hoTotalValue "2000000000" True To bTemp2
If ((iTemp1 = 10) And (bTemp1 <> True) And (bTemp2 <> True)) Begin
Showln "Length exceeds the 2,000,000,000-byte demonstration bound."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoTotalNumber
If (Not(IsComObjectCreated(hoTotalNumber))) Begin
Send CreateComObject of hoTotalNumber
End
Get ComUpdateNumber Of hoTotalNumber "value" sTotalText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComIntOf Of hoTotalNumber "value" To iTotal
Get Create (RefClass(cComChilkatJsonObject)) To hoCheckpoint
If (Not(IsComObjectCreated(hoCheckpoint))) Begin
Send CreateComObject of hoCheckpoint
End
Set ComStrict Of hoCheckpoint To True
Get ComFileExists Of hoFiles sCheckpointFile To bTemp1
If (bTemp1 = True) Begin
Get ComLoadFile Of hoCheckpoint sCheckpointFile To iSuccess
If (iSuccess <> True) Begin
Showln "Invalid checkpoint."
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "path" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sResourcePath True To iSameText4
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "etag" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sEtag True To iSameText5
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "size" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sTotalText True To iSameText6
Get ComStringOf Of hoCheckpoint "account" To sTemp1
Get ComStringOf Of hoConfig "account" To sTemp2
If ((sTemp1 <> sTemp2) Or (iSameText4 <> True) Or (iSameText5 <> True) Or (iSameText6 <> True)) Begin
Showln "The remote blob or checkpoint target changed. Preserve the old partial output and restart separately."
Procedure_Return
End
End
Else Begin
Get ComFileExists Of hoFiles sPartFile To bTemp1
If (bTemp1 = True) Begin
Showln "Partial file exists without its checkpoint; refusing to append."
Procedure_Return
End
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComUpdateString Of hoCheckpoint "account" sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "path" sResourcePath To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "etag" sEtag To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "size" sTotalText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComWriteFile Of hoCheckpoint "qa_data/azure/download-checkpoint.tmp" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not write checkpoint."
Procedure_Return
End
Get ComFileRename Of hoFiles "qa_data/azure/download-checkpoint.tmp" sCheckpointFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not publish checkpoint."
Procedure_Return
End
End
// The immutable checkpoint identifies the version. Actual local length is the resume offset.
// Keep this partial file private, unchanged and exclusive to this one download.
Move "0" To sLocalSize
Get ComFileExists Of hoFiles sPartFile To bTemp1
If (bTemp1 = True) Begin
Get ComFileSizeStr Of hoFiles sPartFile To sLocalSize
Get ComLastMethodSuccess Of hoFiles To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not get partial-file size."
Procedure_Return
End
End
Move sLocalSize To sOffsetText
Get Create (RefClass(cComChilkatStringBuilder)) To hoOffsetValue
If (Not(IsComObjectCreated(hoOffsetValue))) Begin
Send CreateComObject of hoOffsetValue
End
Get ComAppend Of hoOffsetValue sOffsetText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComLength Of hoOffsetValue To iTemp1
Get ComLength Of hoOffsetValue To iTemp2
If ((iTemp1 < 1) Or (iTemp2 > 10)) Begin
Showln "Invalid or oversized length for this bounded example."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoOffsetDigits
If (Not(IsComObjectCreated(hoOffsetDigits))) Begin
Send CreateComObject of hoOffsetDigits
End
Get ComAppend Of hoOffsetDigits sOffsetText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Move 0 To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "0" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "1" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "2" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "3" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "4" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "5" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "6" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "7" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "8" "" To iOffsetRemoved
Get ComReplace Of hoOffsetDigits "9" "" To iOffsetRemoved
Get ComLength Of hoOffsetDigits To iTemp1
If (iTemp1 <> 0) Begin
Showln "Length must be a decimal string."
Procedure_Return
End
Get ComLength Of hoOffsetValue To iTemp1
Get ComStartsWith Of hoOffsetValue "1" True To bTemp1
Get ComContentsEqual Of hoOffsetValue "2000000000" True To bTemp2
If ((iTemp1 = 10) And (bTemp1 <> True) And (bTemp2 <> True)) Begin
Showln "Length exceeds the 2,000,000,000-byte demonstration bound."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoOffsetNumber
If (Not(IsComObjectCreated(hoOffsetNumber))) Begin
Send CreateComObject of hoOffsetNumber
End
Get ComUpdateNumber Of hoOffsetNumber "value" sOffsetText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComIntOf Of hoOffsetNumber "value" To iOffset
If (iOffset > iTotal) Begin
Showln "Partial file is longer than the selected blob."
Procedure_Return
End
// Ensure an empty blob also creates a local file.
Get ComOpenForAppend Of hoFiles sPartFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not open partial file."
Procedure_Return
End
Send ComFileClose To hoFiles
Get ComAddHeader Of hoRest "If-Match" sEtag To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get Create (RefClass(cComChilkatBinData)) To hoChunk
If (Not(IsComObjectCreated(hoChunk))) Begin
Send CreateComObject of hoChunk
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoRange
If (Not(IsComObjectCreated(hoRange))) Begin
Send CreateComObject of hoRange
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoExpectedRange
If (Not(IsComObjectCreated(hoExpectedRange))) Begin
Send CreateComObject of hoExpectedRange
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoExpectedLength
If (Not(IsComObjectCreated(hoExpectedLength))) Begin
Send CreateComObject of hoExpectedLength
End
While (iOffset < iTotal)
Move (iTotal - iOffset) To iCount
If (iCount > 4194304) Begin
Move 4194304 To iCount
End
Move (iOffset + iCount - 1) To iEndByte
Send ComClear To hoRange
Get ComAppend Of hoRange "bytes=" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppendInt Of hoRange iOffset To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoRange "-" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppendInt Of hoRange iEndByte To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComGetAsString Of hoRange To sTemp1
Get ComAddHeader Of hoRest "x-ms-range" sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Send ComClear To hoExpectedRange
Get ComAppend Of hoExpectedRange "bytes " To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppendInt Of hoExpectedRange iOffset To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoExpectedRange "-" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppendInt Of hoExpectedRange iEndByte To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoExpectedRange "/" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoExpectedRange sTotalText To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Send ComClear To hoExpectedLength
Get ComAppendInt Of hoExpectedLength iCount To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComDisconnect Of hoRest 10 To iSuccess
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS reconnection failed."
Procedure_Return
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComSendReqNoBody Of hoRest "GET" sResourcePath To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComReadResponseHeader Of hoRest To iHttpStatus
If (iHttpStatus < 0) Begin
Showln "Could not read range response headers."
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 206) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "HTTP status: " iTemp1
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Showln "Azure error code: " sTemp1
Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
Showln "Request ID: " sTemp1
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "ETag" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sEtag True To iSameText7
Get ComResponseHdrByName Of hoRest "Content-Range" To sTemp1
Get ComGetAsString Of hoExpectedRange To sTemp2
Get ComResponseHdrByName Of hoRest "Content-Length" To sTemp3
Get ComGetAsString Of hoExpectedLength To sTemp4
If ((iSameText7 <> True) Or (sTemp1 <> sTemp2) Or (sTemp3 <> sTemp4)) Begin
Showln "Unexpected range response; no bytes appended."
Procedure_Return
End
Get ComClear Of hoChunk To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get pvComObject of hoChunk to vChunk
Get ComReadRespBd Of hoRest vChunk To iSuccess
If (iSuccess <> True) Begin
Showln "Incomplete range body; no bytes appended."
Procedure_Return
End
Get ComNumBytes Of hoChunk To iTemp1
If (iTemp1 <> iCount) Begin
Showln "Wrong byte count; no bytes appended."
Procedure_Return
End
Get ComOpenForAppend Of hoFiles sPartFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not reopen partial file."
Procedure_Return
End
Get pvComObject of hoChunk to vChunk
Get ComFileWriteBd Of hoFiles vChunk 0 0 To iSuccess
Send ComFileClose To hoFiles
If (iSuccess <> True) Begin
Showln "Local write failed. Inspect the partial file before retrying."
Procedure_Return
End
Move (iOffset + iCount) To iOffset
Loop
Get ComFileRename Of hoFiles sPartFile sFinalFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not publish completed download."
Procedure_Return
End
Showln "Download complete. Retain or archive the checkpoint with the completed file."
End_Procedure