ArArchiveKit Documentation

Structure ArArchive​Writer

public struct ArArchiveWriter  

ArArchiveWriter creates ar files.

import Foundation

var writer = ArArchiveWriter()
writer.addFile(header: Header(name: "hello.txt", modificationTime: Int(Date().timeIntervalSince1970)), contents: "Hello, World!")
let data = Data(writer.finalize())

Initializers

init(variant:​)

public init(variant: Variant = .common)  

Properties

variant

public let variant: Variant

Methods

add​File(header:​contents:​)

public mutating func addFile(header: Header, contents: [UInt8])  

Add a file to the archive.

Parameters

header Header

The header that describes the file.

contents [UInt8]

The raw bytes of the file.

add​File(header:​contents:​)

public mutating func addFile(header: Header, contents: String)  

Wrapper function around ArArchiveWriter.addFile(header:contents:) which allows you to pass in a String instead of raw bytes..

finalize(clear:​)

public mutating func finalize(clear: Bool = true) -> [UInt8]  

Creates an archive and returns the bytes of the created archive.

Parameters

clear Bool

Whether the data in self.bytes and self.headers should be cleared. If clear is true, then you can reuse this ArArchiveWriter.

Returns

The bytes of the created archive.