Skip to content

Instantly share code, notes, and snippets.

@dmaclach
Last active December 3, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmaclach/637a6ba854fd70d2cd63e026b635430d to your computer and use it in GitHub Desktop.
Save dmaclach/637a6ba854fd70d2cd63e026b635430d to your computer and use it in GitHub Desktop.
Apple Archive Example In Objective-C
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *dst =
[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/file.aar"];
AAByteStream fileStream = AAFileStreamOpenWithPath(dst.UTF8String,
O_CREAT | O_WRONLY, 0644);
AAByteStream compressionStream = AACompressionOutputStreamOpen(fileStream,
AA_COMPRESSION_ALGORITHM_LZFSE, 1<<20, AA_FLAG_VERBOSITY_3, 0);
AAArchiveStream encodeStream = AAEncodeArchiveOutputStreamOpen(compressionStream,
NULL, NULL, AA_FLAG_VERBOSITY_3, 0);
NSString *src = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/Endpoint"];
AAPathList pathList = AAPathListCreateWithDirectoryContents(src.UTF8String,
NULL,
NULL,
NULL,
AA_FLAG_VERBOSITY_3,
0);
AAFieldKeySet keySet = AAFieldKeySetCreateWithString(
"TYP,PAT,LNK,DEV,DAT,UID,GID,MOD,FLG,MTM,BTM,CTM");
int outVal = AAArchiveStreamWritePathList(encodeStream, pathList, keySet,
src.UTF8String, NULL, NULL,
AA_FLAG_VERBOSITY_3, 0);
NSLog(@"AAArchiveStreamWritePathList %d", outVal);
outVal = AAArchiveStreamClose(encodeStream);
NSLog(@"AAArchiveStreamClose %d", outVal);
AAFieldKeySetDestroy(keySet);
AAPathListDestroy(pathList);
outVal = AAByteStreamClose(compressionStream);
NSLog(@"AAByteStreamClose %d", outVal);
outVal = AAByteStreamClose(fileStream);
NSLog(@"AAByteStreamClose %d", outVal);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment