Class
ZipSource
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:freeWhenDone:)
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
Name | Type | Description |
---|---|---|
buffer | UnsafeRawPointer |
data buffer |
length | Int |
data size |
freeWhenDone | Bool |
buffer ownership flag |
init(buffer:freeWhenDone:)
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
Name | Type | Description |
---|---|---|
buffer | UnsafeRawBufferPointer |
data buffer |
freeWhenDone | 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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
file | UnsafeMutablePointer<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
Name | Type | Description |
---|---|---|
callback | @escaping zip_source_callback |
user-defined callback function |
userdata | UnsafeMutableRawPointer? |
custom data to be passed to |
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
Name | Type | Description |
---|---|---|
callback | user-provided callback instance |
init(data:)
public convenience init(data: Data) throws