CPIOArchiveKit Documentation

Structure CPIOArchive​Writer

public struct CPIOArchiveWriter  

CPIOArchiveWriter creates cpio archives.

let writer = CPIOArchiveWriter()

let header = Header(
	name: "hello.txt",
	mode: FileMode(0o644),
	modificationTime: Int(Date().timeIntervalSince1970)
)
writer.addFile(header: header, contents: "Hello World!")
writer.finalize()
// Use `writer.bytes`.

Initializers

init(type:​)

public init(type: CPIOArchiveType = .svr4)  

Creates a new CPIOArchiveWriter.

Parameters

type CPIOArchive​Type

The type of cpio archive you would like CPIOArchiveWriter to create.

Properties

archive​Type

public let archiveType: CPIOArchiveType

The type of archive that CPIOArchiveWriter will create.

Methods

add​File(header:​contents:​)

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

Add a file to the archive.

Symlinks

Add a symlink by setting header.name to the name you want the symlink to have, and contents to the name of the file you want to link to.

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 CPIOArchiveWriter.addFile(header:contents:) which allows you to pass in a String instead of raw bytes..

Symlinks

Add a symlink by setting header.name to the name you want the symlink to have, and contents to the name of the file you want to link to.

finalize(clear:​)

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

Creates the archive and returns the bytes of the archive.