PrivMXStoreFileHandlerExtensions
A class providing a set of tools using SwiftNIO for uploading and downloading files with the use of PrivMXStore
from PrivMX Endpoint.
Static Methods
getStoreFileUpdater(for:withReplacement:using:replacingPublicMeta:replacingPrivateMeta:replacingFileSize:chunkSize:)
Creates a handler for updating a file with a new data buffer.
public static func getStoreFileUpdater(
for fileId:String,
withReplacement sourceFile:FileHandle,
using storesApi:any PrivMXStore,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingFileSize fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
fileId | String | The ID of the file to be updated. |
sourceFile | FileHandle | The FileHandle (swift-nio) with new file content. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
publicMeta | Data | The new public metadata for the file. |
privateMeta | Data | The new private metadata for the file. |
fileSize | Int64 | The size of the file to be updated. |
chunkSize | Int64 | The size of the chunks for the upload. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for updating the file. |
getStoreFileCreator(inStore:from:using:withPublicMeta:withPrivateMeta:fileSize:chunkSize:)
Creates a handler for creating a new file from a data buffer.
public static func getStoreFileCreator(
inStore storeId:String,
from sourceFile:FileHandle,
using storesApi:any PrivMXStore,
withPublicMeta publicMeta:Data,
withPrivateMeta privateMeta:Data,
fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
storeId | String | The ID of the store where the file will be created. |
sourceFile | FileHandle | The FileHandle (swift-nio) with new file content. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
publicMeta | Data | The public metadata for the new file. |
privateMeta | Data | The private metadata for the new file. |
fileSize | Int64 | The size of the new file. |
chunkSize | Int64 | The size of the chunks for the upload. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for creating the file. |
getStoreFileUpdater(for:withReplacementBuffer:using:replacingPublicMeta:replacingPrivateMeta:replacingFileSize:chunkSize:)
Creates a handler for updating a file with a new data buffer.
public static func getStoreFileUpdater(
for fileId:String,
withReplacementBuffer sourceBuffer:Data,
using storesApi:any PrivMXStore,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingFileSize fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
fileId | String | The ID of the file to be updated. |
sourceBuffer | Data | The data buffer to replace the existing file content. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
publicMeta | Data | The new public metadata for the file. |
privateMeta | Data | The new private metadata for the file. |
fileSize | Int64 | The size of the file to be updated. |
chunkSize | Int64 | The size of the chunks for the upload. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for updating the file. |
getStoreFileCreator(inStore:fromBuffer:using:withPublicMeta:withPrivateMeta:fileSize:chunkSize:)
Creates a handler for updating a file with a new data buffer.
public static func getStoreFileCreator(
inStore storeId:String,
fromBuffer sourceBuffer:Data,
using storesApi:any PrivMXStore,
withPublicMeta publicMeta:Data,
withPrivateMeta privateMeta:Data,
fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
storeId | String | |
sourceBuffer | Data | The data buffer to replace the existing file content. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
publicMeta | Data | The new public metadata for the file. |
privateMeta | Data | The new private metadata for the file. |
fileSize | Int64 | The size of the file to be updated. |
chunkSize | Int64 | The size of the chunks for the upload. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for updating the file. |
getStoreFileReader(saveTo:readFrom:with:chunkSize:)
Creates a new handler for downloading a file and saving it to a local file.
public static func getStoreFileReader(
saveTo outputFile:FileHandle,
readFrom fileId:String,
with storesApi:any PrivMXStore,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
outputFile | FileHandle | The local file handle (swift-nio) where the downloaded file content will be saved. |
fileId | String | The ID of the file to be downloaded from the `PrivMXStore`. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
chunkSize | Int64 | The size of the chunks for downloading. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for downloading the file to the local file. |
getStoreFileReader(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 getStoreFileReader(
readFrom fileId:String,
with storesApi:any PrivMXStore,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler
Name | Type | Description |
---|---|---|
fileId | String | The ID of the file to be downloaded from the `PrivMXStore`. |
storesApi | any PrivMXStore | The API for interacting with the `PrivMXStore`. |
chunkSize | Int64 | The size of the chunks for downloading. Defaults to the recommended chunk size. |
Type | Description |
---|---|
PrivMXStoreFileHandler | A new `PrivMXStoreFileHandler` instance configured for downloading the file into the buffer. |