InboxFileHandler
A class providing a set of tools using SwiftNIO for uploading and downloading files with the use of PrivMXInbox
from PrivMX Endpoint.
Fields
RecommendedChunkSize
Recommended chunk size for file transfers, suggested by the endpoint library.
public static let RecommendedChunkSize :Int64 = 131072
fileHandle
InboxFileHandle
public let fileHandle:privmx.InboxFileHandle
mode
The mode of this handler
public let mode:InboxFileHandlerMode
hasDataLeft
public private(set) var hasDataLeft:Bool = true
Static Methods
getInboxFileReaderToBuffer(readFrom:with:chunkSize:)
Creates a new handler for downloading a file to an internal buffer.
This method allows downloading a file from the PrivMXStore
directly into memory (a buffer). To retrieve the buffer after the download, call getBuffer()
.
public static func getInboxFileReaderToBuffer(
readFrom fileId:String,
with inboxApi:any PrivMXInbox,
chunkSize: Int64 = InboxFileHandler.RecommendedChunkSize
) throws -> InboxFileHandler
Name | Type | Description |
---|---|---|
fileId | String | The ID of the file to be downloaded from the `PrivMXStore`. |
inboxApi | any PrivMXInbox | |
chunkSize | Int64 | The size of the chunks for downloading. Defaults to the recommended chunk size. |
Type | Description |
---|---|
InboxFileHandler | A new `PrivMXStoreFileHandler` instance configured for downloading the file into the buffer. |
getInboxFileReaderToFile(readFrom:with:to:chunkSize:)
Creates a new handler for downloading a file to a local File.
This method allows downloading a file from the PrivMXStore
directly into memory (a buffer). To retrieve the buffer after the download, call getBuffer()
.
public static func getInboxFileReaderToFile(
readFrom fileId:String,
with inboxApi:any PrivMXInbox,
to localFile:FileHandle,
chunkSize: Int64 = InboxFileHandler.RecommendedChunkSize
) throws -> InboxFileHandler
Name | Type | Description |
---|---|---|
fileId | String | The ID of the file to be downloaded from the `PrivMXStore`. |
inboxApi | any PrivMXInbox | |
localFile | FileHandle | SwiftNIO handle to a file on the device |
chunkSize | Int64 | The size of the chunks for downloading. Defaults to the recommended chunk size. |
Type | Description |
---|---|
InboxFileHandler | A new `PrivMXStoreFileHandler` instance configured for downloading the File into the local file. |
Methods
setInboxHandle(_:)
Sets the Inbox handle for uploading the file.
public func setInboxHandle(
_ handle: privmx.InboxHandle
) -> Void
Name | Type | Description |
---|---|---|
handle | privmx.InboxHandle | Inbox handle received by preparing an Inbox Entry |
getBuffer()
Provides access to the data buffer of the processed file.
public func getBuffer(
) -> Data?
Type | Description |
---|---|
Data? | The processed data buffer. |
closeSource()
Closes local FileDataSource
.
public func closeSource(
) throws -> Void
closeRemote()
Closes remote File.
public func closeRemote(
) throws -> String
Type | Description |
---|---|
String | Id of the remote File. |
readChunk(onChunkDownloaded:)
Downloads the next chunk and adds it to either the local file or the internal buffer, depending on the mode.
public func readChunk(
onChunkDownloaded: @escaping ((Int)->Void) = {byteCount in}
) throws -> Void
Name | Type | Description |
---|---|---|
onChunkDownloaded | @escaping ((Int) -> Void) | A closure called when a chunk is downloaded, passing the byte count of the chunk. |
writeChunk(onChunkUploaded:)
Uploads the next chunk of data from the local file or buffer to the remote file.
public func writeChunk(
onChunkUploaded: @escaping ((Int) -> Void) = {byteCount in}
) throws -> Void
Name | Type | Description |
---|---|---|
onChunkUploaded | @escaping ((Int) -> Void) | A closure called when a chunk is uploaded, passing the byte count of the chunk. |