Amazon Glacier: Resume an Archive Download with Verified Chunks
See more Amazon Glacier Examples
For existing Amazon Glacier vault customers. The standalone vault service is closed to new customers. These examples use its REST API version 2012-06-01, not the S3 bucket APIs used by S3 Glacier storage classes. See AWS service guidance.
Downloads a completed full-archive retrieval job in fixed 8 MiB ranges. Set the job ID, cache directory, and final path. Start with an empty, private cache directory on the same filesystem as the final output, then rerun with exactly the same settings to resume. Only one process may use the directory. No new retrieval job is initiated, even if the old job expires.
A saved identity binds progress to region, vault, job, archive ID, size, tree hash, chunk size, and final path. Every cached chunk is rehashed and its length and range checked before reuse. New chunks require HTTP 206, exact Content-Range and Content-Length, actual length, and a matching response tree hash before their temporary file is committed. An interrupted chunk is downloaded again; already verified chunks are retained. A damaged checkpoint or cached chunk stops with an explanation. Local cache files and receipts must be protected from other writers.
After downloading, the example assembles one chunk at a time and checks the entire file's byte count and archive tree hash before renaming it. Interrupted assembly is rebuilt from the cache. Existing final output is accepted only if it matches; other files are not overwritten. Chunks remain for inspection or manual cleanup. Allow disk space for both the complete chunk cache and assembled archive, plus one temporary chunk. A disk-full, network, or checksum failure is not success.
Uses decimal strings and bounded 32-bit arithmetic for archive offsets through the 40 TiB archive limit, including beyond 2 GiB. This produces up to 5,242,880 chunk files plus receipts at that limit; larger power-of-two chunks are more practical for very large archives, but require adapting the arithmetic and checkpoint schema. Empty archives use the single-download example. For partial retrieval jobs use range output download instead.
Requires glacier:DescribeJob and glacier:GetJobOutput. Resume promptly while output is retained (at least 24 hours after successful completion). If it has expired, initiate a new retrieval deliberately and use a new cache directory; cached chunks are not automatically transferred to a different job.
Uses AWS Signature Version 4 with service glacier. Set the region once; the example builds the commercial AWS endpoint. Other partitions require the appropriate endpoint suffix. /-/ selects the signing account; change the vault name and IDs to your own resources. Load private qa_data/aws/glacier.json with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This sample does not discover profiles or refresh credentials. TLS certificate verification is enabled explicitly.
Checks transport completion, the operation-specific HTTP status, and parsed data separately. Inspect full diagnostics privately. Renew expired credentials; use bounded backoff with jitter for retryable reads. Uploads and job initiation can succeed before a connection fails, so do not blindly resubmit them. Configure IAM permissions for only the required operations and vault resources.
Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoStringBuilder.h>
#import <CkoAuthAws.h>
#import <CkoRest.h>
#import <CkoSocket.h>
#import <CkoFileAccess.h>
#import <CkoDirTree.h>
#import <CkoCrypt2.h>
#import <CkoStream.h>
#import <CkoBinData.h>
// Assumes Chilkat is unlocked. See Global Unlock Sample.
BOOL success = NO;
// Private configuration, not a file in public web content or source control.
// Load current IAM credentials authorized for the Glacier operation.
CkoJsonObject *credentials = [[CkoJsonObject alloc] init];
credentials.Strict = YES;
success = [credentials LoadFile: @"qa_data/aws/glacier.json"];
if (success != YES) {
NSLog(@"%@",@"Could not load private AWS credentials.");
return;
}
if (([[credentials JsonTypeOf: @"access_key"] intValue] != 1) || ([credentials StringOf: @"access_key"] == @"")) {
NSLog(@"%@",@"Missing or invalid access_key.");
return;
}
if (([[credentials JsonTypeOf: @"secret_key"] intValue] != 1) || ([credentials StringOf: @"secret_key"] == @"")) {
NSLog(@"%@",@"Missing or invalid secret_key.");
return;
}
// Set this once to the region containing the vault.
NSString *region = @"us-west-2";
CkoStringBuilder *endpoint = [[CkoStringBuilder alloc] init];
[endpoint Append: @"glacier."];
[endpoint Append: region];
[endpoint Append: @".amazonaws.com"];
CkoAuthAws *aws = [[CkoAuthAws alloc] init];
aws.AccessKey = [credentials StringOf: @"access_key"];
aws.SecretKey = [credentials StringOf: @"secret_key"];
aws.Region = region;
aws.ServiceName = @"glacier";
aws.SignatureVersion = [NSNumber numberWithInt:4];
CkoRest *rest = [[CkoRest alloc] init];
rest.ConnectTimeoutMs = [NSNumber numberWithInt:20000];
rest.IdleTimeoutMs = [NSNumber numberWithInt:60000];
success = [rest SetAuthAws: aws];
if (success != YES) {
NSLog(@"%@",@"Could not configure AWS signing.");
return;
}
// Temporary IAM/STS credentials require their session token on every signed request.
// Include the token in the signed query. Keep request URLs and diagnostics private.
// Leave session_token absent or empty only for credentials that do not have one.
if ([credentials HasMember: @"session_token"] == YES) {
if ([[credentials JsonTypeOf: @"session_token"] intValue] != 1) {
NSLog(@"%@",@"session_token must be a string.");
return;
}
if ([credentials StringOf: @"session_token"] != @"") {
success = [rest AddQueryParam: @"X-Amz-Security-Token" value: [credentials StringOf: @"session_token"]];
if (success != YES) {
NSLog(@"%@",@"Could not set the session-token parameter.");
return;
}
}
}
// Supply a Socket to explicitly enable TLS certificate verification.
CkoSocket *connection = [[CkoSocket alloc] init];
connection.RequireSslCertVerify = YES;
connection.MaxReadIdleMs = [NSNumber numberWithInt:60000];
connection.MaxSendIdleMs = [NSNumber numberWithInt:60000];
success = [connection Connect: [endpoint GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 20000]];
if (success != YES) {
NSLog(@"%@",@"TLS connection failed; inspect diagnostics privately.");
return;
}
success = [rest UseConnection: connection autoReconnect: YES];
if (success != YES) {
NSLog(@"%@",@"Could not attach the TLS connection.");
return;
}
success = [rest AddHeader: @"x-amz-glacier-version" value: @"2012-06-01"];
if (success != YES) {
NSLog(@"%@",@"Could not set x-amz-glacier-version.");
return;
}
// A hyphen selects the account belonging to the signing credentials.
// Use the original, URL-safe vault name and IDs returned by Glacier.
success = [rest AddPathParam: @"{vault}" value: @"chilkat"];
if (success != YES) {
NSLog(@"%@",@"Could not set vault name.");
return;
}
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
CkoJsonObject *error = [[CkoJsonObject alloc] init];
error.Strict = YES;
CkoStringBuilder *responseBody = [[CkoStringBuilder alloc] init];
NSString *jobId = @"YOUR_JOB_ID";
success = [rest AddPathParam: @"{job}" value: jobId];
if (success != YES) {
NSLog(@"%@",@"Could not set job ID.");
return;
}
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/-/vaults/{vault}/jobs/{job}" sb: responseBody];
if (success != YES) {
NSLog(@"%@",@"Request did not complete; inspect diagnostics privately. Check state before retrying a change.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"Glacier HTTP status: ",[rest.ResponseStatusCode intValue]);
success = [error LoadSb: responseBody];
if (success == YES) {
if ([[error JsonTypeOf: @"code"] intValue] == 1) {
NSLog(@"%@%@",@"AWS error code: ",[error StringOf: @"code"]);
}
}
NSLog(@"%@%@",@"AWS request ID: ",[rest ResponseHdrByName: @"x-amzn-RequestId"]);
// Inspect full errors privately. An HTTP error is not a successful operation.
return;
}
success = [result LoadSb: responseBody];
if (success != YES) {
NSLog(@"%@",@"Expected valid JSON response.");
return;
}
if ([[result JsonTypeOf: @"Completed"] intValue] != 5) {
NSLog(@"%@",@"Missing or invalid Completed.");
return;
}
if ([[result JsonTypeOf: @"StatusCode"] intValue] != 1) {
NSLog(@"%@",@"Missing or invalid StatusCode.");
return;
}
if ([result StringOf: @"StatusCode"] == @"") {
NSLog(@"%@",@"Empty StatusCode.");
return;
}
if (([result BoolOf: @"Completed"] != YES) || ([result StringOf: @"StatusCode"] != @"Succeeded")) {
NSLog(@"%@",@"Job is not successfully complete. Resume later only if InProgress.");
return;
}
if ([result StringOf: @"Action"] != @"ArchiveRetrieval") {
NSLog(@"%@",@"Wrong job type.");
return;
}
if ([[result JsonTypeOf: @"SHA256TreeHash"] intValue] != 1) {
NSLog(@"%@",@"Missing or invalid SHA256TreeHash.");
return;
}
if ([result StringOf: @"SHA256TreeHash"] == @"") {
NSLog(@"%@",@"Empty SHA256TreeHash.");
return;
}
if ([[result JsonTypeOf: @"ArchiveSizeInBytes"] intValue] != 2) {
NSLog(@"%@",@"Missing or invalid ArchiveSizeInBytes.");
return;
}
if ([[result JsonTypeOf: @"ArchiveId"] intValue] != 1) {
NSLog(@"%@",@"Missing or invalid ArchiveId.");
return;
}
if ([result StringOf: @"ArchiveId"] == @"") {
NSLog(@"%@",@"Empty ArchiveId.");
return;
}
if ([[result JsonTypeOf: @"ArchiveSHA256TreeHash"] intValue] != 1) {
NSLog(@"%@",@"Missing or invalid ArchiveSHA256TreeHash.");
return;
}
if ([result StringOf: @"ArchiveSHA256TreeHash"] == @"") {
NSLog(@"%@",@"Empty ArchiveSHA256TreeHash.");
return;
}
NSString *expectedSize = [result StringOf: @"ArchiveSizeInBytes"];
NSString *expectedHash = [result StringOf: @"ArchiveSHA256TreeHash"];
if ([result StringOf: @"SHA256TreeHash"] != expectedHash) {
NSLog(@"%@",@"Use a full-archive retrieval job for this resumable example.");
return;
}
// Fixed 8 MiB chunks are power-of-two and tree-hash aligned.
// Decimal long division avoids 32-bit overflow in every generated language.
int chunkSize = 8388608;
int chunkCount = 0;
int remainder = 0;
int position = 0;
CkoStringBuilder *sizeText = [[CkoStringBuilder alloc] init];
CkoStringBuilder *decimalDigits = [[CkoStringBuilder alloc] init];
CkoStringBuilder *digit = [[CkoStringBuilder alloc] init];
[sizeText Append: expectedSize];
[decimalDigits Append: @"0123456789"];
if (([sizeText.Length intValue] == 0) || ([sizeText.Length intValue] > 14)) {
NSLog(@"%@",@"Invalid archive size.");
return;
}
while ((position < [sizeText.Length intValue])) {
[digit SetString: [sizeText GetRange: [NSNumber numberWithInt: position] numChars: [NSNumber numberWithInt: 1] removeFlag: NO]];
if ([decimalDigits Contains: [digit GetAsString] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid decimal archive size.");
return;
}
remainder = remainder * 10 + [digit.IntValue intValue];
// At most nine subtractions per digit; avoids language-specific division.
chunkCount = chunkCount * 10;
while ((remainder >= chunkSize)) {
chunkCount = chunkCount + 1;
remainder = remainder - chunkSize;
}
position = position + 1;
}
if ((chunkCount > 5242880) || ((chunkCount == 5242880) && (remainder != 0))) {
NSLog(@"%@",@"Archive exceeds the 40 TiB service limit.");
return;
}
if ((chunkCount == 0) && (remainder == 0)) {
NSLog(@"%@",@"Use the single-download example for an empty archive.");
return;
}
if (remainder != 0) {
chunkCount = chunkCount + 1;
}
// This dedicated directory belongs to ONE job. Use a new empty directory
// when selecting another job. Run only one process against it at a time.
NSString *cacheDir = @"qa_output/glacier-download";
NSString *finalPath = @"qa_output/archive-resumed.dat";
CkoFileAccess *files = [[CkoFileAccess alloc] init];
success = [files DirEnsureExists: cacheDir];
if (success != YES) {
NSLog(@"%@",@"Could not create private download directory.");
return;
}
CkoStringBuilder *path = [[CkoStringBuilder alloc] init];
[path Append: cacheDir];
[path Append: @"/manifest.json"];
NSString *manifestPath = [path GetAsString];
CkoJsonObject *manifest = [[CkoJsonObject alloc] init];
manifest.Strict = YES;
CkoJsonObject *identity = [[CkoJsonObject alloc] init];
success = [identity UpdateString: @"version" value: @"1"];
if (success != YES) {
NSLog(@"%@",@"Could not set version.");
return;
}
success = [identity UpdateString: @"region" value: region];
if (success != YES) {
NSLog(@"%@",@"Could not set region.");
return;
}
success = [identity UpdateString: @"vault" value: @"chilkat"];
if (success != YES) {
NSLog(@"%@",@"Could not set vault.");
return;
}
success = [identity UpdateString: @"jobId" value: jobId];
if (success != YES) {
NSLog(@"%@",@"Could not set jobId.");
return;
}
success = [identity UpdateString: @"archiveId" value: [result StringOf: @"ArchiveId"]];
if (success != YES) {
NSLog(@"%@",@"Could not set archiveId.");
return;
}
success = [identity UpdateString: @"size" value: expectedSize];
if (success != YES) {
NSLog(@"%@",@"Could not set size.");
return;
}
success = [identity UpdateString: @"treeHash" value: expectedHash];
if (success != YES) {
NSLog(@"%@",@"Could not set treeHash.");
return;
}
success = [identity UpdateString: @"chunkSize" value: @"8388608"];
if (success != YES) {
NSLog(@"%@",@"Could not set chunkSize.");
return;
}
success = [identity UpdateString: @"finalPath" value: finalPath];
if (success != YES) {
NSLog(@"%@",@"Could not set finalPath.");
return;
}
if ([files FileExists: manifestPath] == YES) {
success = [manifest LoadFile: manifestPath];
if (success != YES) {
NSLog(@"%@",@"Invalid checkpoint. Preserve the cache and inspect it before restarting.");
return;
}
if ([manifest StringOf: @"version"] != [identity StringOf: @"version"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"region"] != [identity StringOf: @"region"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"vault"] != [identity StringOf: @"vault"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"jobId"] != [identity StringOf: @"jobId"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"archiveId"] != [identity StringOf: @"archiveId"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"size"] != [identity StringOf: @"size"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"treeHash"] != [identity StringOf: @"treeHash"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"chunkSize"] != [identity StringOf: @"chunkSize"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
if ([manifest StringOf: @"finalPath"] != [identity StringOf: @"finalPath"]) {
NSLog(@"%@",@"Checkpoint belongs to different download settings. Use a new empty cache directory.");
return;
}
}
else {
CkoDirTree *cacheContents = [[CkoDirTree alloc] init];
cacheContents.BaseDir = cacheDir;
cacheContents.Recurse = NO;
success = [cacheContents BeginIterate];
if ((success == YES) || (cacheContents.DoneIterating != YES)) {
NSLog(@"%@",@"First run requires an empty, readable cache directory.");
return;
}
success = [identity WriteFile: manifestPath];
if (success != YES) {
NSLog(@"%@",@"Could not save download identity.");
return;
}
}
CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init];
crypt.HashAlgorithm = @"sha256-tree-hash";
crypt.EncodingMode = @"hexlower";
if ([files FileExists: finalPath] == YES) {
NSString *finalSize = [files FileSizeStr: finalPath];
NSString *finalHash = [crypt HashFileENC: finalPath];
if ((crypt.LastMethodSuccess != YES) || (finalSize != expectedSize) || (finalHash != expectedHash)) {
NSLog(@"%@",@"Existing final file differs; choose another final output path.");
return;
}
NSLog(@"%@",@"Archive already downloaded and verified.");
return;
}
CkoStringBuilder *rangeHeader = [[CkoStringBuilder alloc] init];
CkoStringBuilder *contentRange = [[CkoStringBuilder alloc] init];
CkoStringBuilder *byteCount = [[CkoStringBuilder alloc] init];
CkoJsonObject *receipt = [[CkoJsonObject alloc] init];
receipt.Strict = YES;
int chunkIndex = 0;
int byteHigh = 0;
int byteLow = 0;
int endHigh;
int endLow;
CkoStringBuilder *range = [[CkoStringBuilder alloc] init];
CkoStringBuilder *digits = [[CkoStringBuilder alloc] init];
while ((chunkIndex < chunkCount)) {
int chunkBytes = chunkSize;
if ((chunkIndex == chunkCount - 1) && (remainder != 0)) {
chunkBytes = remainder;
}
[range Clear];
[digits Clear];
[digits AppendInt: [NSNumber numberWithInt: byteLow]];
if (byteHigh > 0) {
while (([digits.Length intValue] < 9)) {
[digits Prepend: @"0"];
}
[range AppendInt: [NSNumber numberWithInt: byteHigh]];
}
[range Append: [digits GetAsString]];
[range Append: @"-"];
endHigh = byteHigh;
endLow = byteLow + chunkBytes - 1;
if (endLow >= 1000000000) {
endLow = endLow - 1000000000;
endHigh = endHigh + 1;
}
[digits Clear];
[digits AppendInt: [NSNumber numberWithInt: endLow]];
if (endHigh > 0) {
while (([digits.Length intValue] < 9)) {
[digits Prepend: @"0"];
}
[range AppendInt: [NSNumber numberWithInt: endHigh]];
}
[range Append: [digits GetAsString]];
NSString *rangeKey = [range GetAsString];
[rangeHeader SetString: @"bytes="];
[rangeHeader Append: rangeKey];
[contentRange SetString: @"bytes "];
[contentRange Append: rangeKey];
[contentRange Append: @"/"];
[contentRange Append: expectedSize];
[byteCount Clear];
[byteCount AppendInt: [NSNumber numberWithInt: chunkBytes]];
[path SetString: cacheDir];
[path Append: @"/chunk-"];
[path AppendInt: [NSNumber numberWithInt: chunkIndex]];
NSString *chunkPath = [path GetAsString];
[path Append: @".json"];
NSString *receiptPath = [path GetAsString];
[path SetString: chunkPath];
[path Append: @".part"];
NSString *temporaryPath = [path GetAsString];
if ([files FileExists: chunkPath] == YES) {
success = [receipt LoadFile: receiptPath];
if (success != YES) {
NSLog(@"%@",@"Cached chunk lacks a valid receipt. Preserve the cache and inspect it.");
return;
}
NSString *cachedHash = [crypt HashFileENC: chunkPath];
if ((crypt.LastMethodSuccess != YES) || (cachedHash != [receipt StringOf: @"treeHash"]) || ([receipt StringOf: @"range"] != rangeKey) || ([files FileSizeStr: chunkPath] != [byteCount GetAsString])) {
NSLog(@"%@",@"Cached chunk failed verification. Remove only that chunk and its receipt, then rerun.");
return;
}
NSLog(@"%@%d",@"Reusing verified chunk: ",chunkIndex);
}
else {
success = [rest AddHeader: @"Range" value: [rangeHeader GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not set Range.");
return;
}
success = [rest SendReqNoBody: @"GET" uriPath: @"/-/vaults/{vault}/jobs/{job}/output"];
if (success != YES) {
NSLog(@"%@",@"Could not send range request. Rerun to resume.");
return;
}
int httpStatus = [[rest ReadResponseHeader] intValue];
if (httpStatus != 206) {
NSLog(@"%@",@"Expected HTTP 206 for range download. Job may have expired; no new retrieval was started.");
return;
}
NSString *responseRange = [rest ResponseHdrByName: @"Content-Range"];
if ((rest.LastMethodSuccess != YES) || (responseRange != [contentRange GetAsString])) {
NSLog(@"%@",@"Unexpected Content-Range; refusing download.");
return;
}
NSString *responseLength = [rest ResponseHdrByName: @"Content-Length"];
if ((rest.LastMethodSuccess != YES) || (responseLength != [byteCount GetAsString])) {
NSLog(@"%@",@"Unexpected Content-Length; refusing download.");
return;
}
NSString *responseHash = [rest ResponseHdrByName: @"x-amz-sha256-tree-hash"];
if ((rest.LastMethodSuccess != YES) || (responseHash == @"")) {
NSLog(@"%@",@"Missing range tree hash. Require a tree-hash-aligned retrieval and download range.");
return;
}
CkoStream *output = [[CkoStream alloc] init];
output.SinkFile = temporaryPath;
success = [rest ReadRespBodyStream: output autoSetStreamCharset: YES];
if (success != YES) {
NSLog(@"%@",@"Download interrupted; rerun to resume. Temporary bytes are not trusted.");
return;
}
NSString *actualSize = [files FileSizeStr: temporaryPath];
if ((files.LastMethodSuccess != YES) || (actualSize != [byteCount GetAsString])) {
NSLog(@"%@",@"Downloaded size mismatch.");
return;
}
NSString *actualHash = [crypt HashFileENC: temporaryPath];
if ((crypt.LastMethodSuccess != YES) || (actualHash != responseHash)) {
NSLog(@"%@",@"Downloaded tree hash mismatch.");
return;
}
success = [receipt UpdateString: @"range" value: rangeKey];
if (success != YES) {
NSLog(@"%@",@"Could not set range.");
return;
}
success = [receipt UpdateString: @"treeHash" value: actualHash];
if (success != YES) {
NSLog(@"%@",@"Could not set treeHash.");
return;
}
success = [receipt WriteFile: receiptPath];
if (success != YES) {
NSLog(@"%@",@"Could not save chunk checksum; temporary bytes remain uncommitted.");
return;
}
success = [files FileRename: temporaryPath newPath: chunkPath];
if (success != YES) {
NSLog(@"%@",@"Could not commit verified chunk.");
return;
}
NSLog(@"%@%d",@"Downloaded verified chunk: ",chunkIndex);
}
byteHigh = endHigh;
byteLow = endLow + 1;
if (byteLow == 1000000000) {
byteLow = 0;
byteHigh = byteHigh + 1;
}
chunkIndex = chunkIndex + 1;
}
// Full-archive size plus hash protects against a partial retrieval job too.
// Assemble from verified chunks; interrupted assembly is rebuilt on rerun.
[path SetString: cacheDir];
[path Append: @"/assembled.part"];
NSString *assembledPath = [path GetAsString];
CkoFileAccess *assembled = [[CkoFileAccess alloc] init];
success = [assembled OpenForWrite: assembledPath];
if (success != YES) {
NSLog(@"%@",@"Could not open assembly file.");
return;
}
CkoBinData *data = [[CkoBinData alloc] init];
chunkIndex = 0;
while ((chunkIndex < chunkCount)) {
[path SetString: cacheDir];
[path Append: @"/chunk-"];
[path AppendInt: [NSNumber numberWithInt: chunkIndex]];
[data Clear];
success = [data LoadFile: [path GetAsString]];
if (success == YES) {
success = [assembled FileWriteBd: data offset: [NSNumber numberWithInt: 0] numBytes: [NSNumber numberWithInt: 0]];
}
if (success != YES) {
[assembled FileClose];
NSLog(@"%@",@"Assembly failed. Verified chunks are retained for resume.");
return;
}
chunkIndex = chunkIndex + 1;
}
[assembled FileClose];
NSString *assembledSize = [files FileSizeStr: assembledPath];
NSString *assembledHash = [crypt HashFileENC: assembledPath];
if ((crypt.LastMethodSuccess != YES) || (assembledSize != expectedSize) || (assembledHash != expectedHash)) {
NSLog(@"%@",@"Assembled archive failed verification; final output was not created.");
return;
}
success = [files FileRename: assembledPath newPath: finalPath];
if (success != YES) {
NSLog(@"%@",@"Verified assembly could not be renamed; keep the cache.");
return;
}
NSLog(@"%@",@"Archive downloaded and verified. Retained chunks can now be removed manually.");