SwiftZip Documentation Beta

Class Zip​Source

public final class ZipSource

A data source.

ZipSource is used for adding or replacing file contents for a file in a zip archive. If the source supports seeking, it can also be used to open zip archives from.

Initializers

init(buffer:​length:​free​When​Done:​)

public convenience init(buffer: UnsafeRawPointer, length: Int, freeWhenDone: Bool) throws

Create a zip source from the buffer data of size length. If freeWhenDone is true, the buffer will be freed when it is no longer needed. buffer must remain valid for the lifetime of the created source.

Parameters

buffer Unsafe​Raw​Pointer

data buffer

length Int

data size

free​When​Done Bool

buffer ownership flag

init(buffer:​free​When​Done:​)

public convenience init(buffer: UnsafeRawBufferPointer, freeWhenDone: Bool) throws

Create a zip source from the buffer data of size length. If freeWhenDone is true, the buffer will be freed when it is no longer needed. buffer must remain valid for the lifetime of the created source.

Parameters

buffer Unsafe​Raw​Buffer​Pointer

data buffer

free​When​Done Bool

buffer ownership flag

init(path:​start:​length:​)

public convenience init(path: String, start: Int = 0, length: Int = -1) throws

Create a zip source from a file. Opens path and read length bytes from offset start from it. If length is 0 or -1, the whole file (starting from start) is used. If the file supports seek, the source can be used to open a zip archive from. The file is opened and read when the data from the source is used.

Parameters

filename

file path to open

start Int

data offset, defaults to 0

length Int

data length, defaults to -1

init(url:​start:​length:​)

public convenience init(url: URL, start: Int = 0, length: Int = -1) throws

Create a zip source from a file. Opens url and read length bytes from offset start from it. If length is 0 or -1, the whole file (starting from start) is used. If the file supports seek, the source can be used to open a zip archive from. The file is opened and read when the data from the source is used.

Parameters

url URL

file URL to open

start Int

data offset, defaults to 0

length Int

data length, defaults to -1

init(file:​start:​length:​)

public convenience init(file: UnsafeMutablePointer<FILE>, start: Int = 0, length: Int = -1) throws

Create a zip source from a file stream. Reads length bytes from offset start from the open file stream file. If length is 0 or -1, the whole file (starting from start) is used. If the file stream supports seeking, the source can be used to open a read-only zip archive from. The file stream is closed when the source is being freed.

Parameters

file Unsafe​Mutable​Pointer<FILE>

file stream to use

start Int

data offset, defaults to 0

length Int

data length, defaults to -1

init(callback:​userdata:​)

public convenience init(callback: @escaping zip_source_callback, userdata: UnsafeMutableRawPointer? = nil) throws

Creates a zip source from the user-provided function callback.

Parameters

callback @escaping zip_source_callback

user-defined callback function

userdata Unsafe​Mutable​Raw​Pointer?

custom data to be passed to callback

init(adapter:​)

public convenience init(adapter: ZipSourceAdapter) throws

Creates a zip source from the user-provided callback instance. The callback must conform to ZipSourceReadable, ZipSourceSeekable, or ZipSourceWritable protocols.

Parameters

callback

user-provided callback instance

init(data:​)

public convenience init(data: Data) throws